Git Introduction – Basic Comments

To set up a GitHub account, simply go to the GitHub website and get started right here GitHub.

To set up Git, go to the Help section of GitHub GitHub Help

, click Set Up Git, select the appropriate operating system, and then follow the instructions below.

Here’s the link you click to actually download Git. Download and Documentation

Introduction about Git, please visit this page : Git Book

For Git Command, please visit this page : Git Commands

we’re going to create a new GitHub repository.

To get started, click on the “New repository” button.

You’ll need to choose a name, and optionally a description.

Choose “Public”, and then let’s check the box .

Click “Create”, and you’re done.

You will see the new repository created :

This “GitDemo” now exists on GitHub only, not your local computer.

To upload project from local machine and make changes to it, such as adding or modifying files , follow below commands.

Go To your folder in your local machine through command prompt :

Step 1 : #Type the command :
git init
Initially no files in local folder

“git status” used to shows the status of changes as untracked, modified, or staged.

Step 2 : Create the first file in the project folder
For window user can use this command to create new file “echo.> Readme.md”

Step 3 : # git isn’t aware of the file, stage it
git add README.md

Step 4 : # take a snapshot of the staging area
git commit -m “add my readme file to initial commit”

Step 5 : # provide the path for the repository you created on github
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git

Step 6 : # push changes to github
git push -u origin master

Example



//Initiate Git setup
C:\Train\GitDemos>git init

//Create New File
C:\Train\GitDemos>echo .> Readme.md

C:\Train\GitDemos>git add Readme.md

C:\Train\GitDemos>git commit -m "add my readme file to initial commit"

//Check log
C:\Train\GitDemos>git log
commit db5d2bf4d8a2749a1aef64fa5b34bc73d302cb2f (HEAD -> master)
Author: Prabakaran K <****@gmail.com>
Date:   Sun Dec 9 12:53:30 2018 +0530

    add my readme file to initial commit

C:\Train\GitDemos>git remote add origin https://github.com/kprabhanew/GitDemo.git

C:\Train\GitDemos>git push -u origin master

//Enter your username password , which we have account in GitHub account
Username for 'https://github.com': *****@gmail.com
Password for 'https://****@gmail.com@github.com':
Enumerating objects: 3, done.

Now After i added new file to project , i do some changes and wants to update in github

How to push a modified file to github repository

git status
It will show you all modified file and new file in working tree

“modified: file path”
Untracked files: that are not tracked by Git

For adding Untracked files

git add<file_path 1>
after adding file you need to commit

git commit -m “< your message>”
For committing only modified file

git commit -m “<your message>” <file_path 1> <file_path2>
Pushing code to git

git push <origin> <branch_name>
# git reset –hard : To reset modified changes in git folder
Now check the github page and refresh the content, we can see the edited local text will be updated

Example Push



C:\Train\TodoApp\Todo4>git commit -a -m "First Changes"

C:\Train\TodoApp\Todo4>git push
Username for 'https://github.com': ****@gmail.com
Password for 'https://*****@gmail.com@github.com':*****

C:\Train\TodoApp\Todo4>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   README.md

Untracked files:
  (use "git add ..." to include in what will be committed)

        db.json
        src/app/api-mock.service.ts
        src/app/api.service.spec.ts

no changes added to commit (use "git add" and/or "git commit -a")

C:\Train\TodoApp\Todo4>git add C:\Train\TodoApp\Todo4
// For individual file (Example : git add "Readme.md")

C:\Train\TodoApp\Todo4>git commit -m "Untracked Files Update"

[master c1b2c21] Untracked Files Update
 28 files changed, 981 insertions(+), 1 deletion(-)
 create mode 100644 db.json
 create mode 100644 src/app/api-mock.service.ts
 create mode 100644 src/app/api.service.spec.ts

C:\Train\TodoApp\Todo4>git push
Username for 'https://github.com': ****@gmail.com
Password for 'https://*****@gmail.com@github.com':

Reference

Leave a Reply

Your email address will not be published. Required fields are marked *