Git Commands

Git Commands

Hello  –

I’m sharing all commands which are used on daily basis. The commands are almost same in Win or Mac Operating Systems. Just use “Git Bash” if you are working on “Windows”, use “Terminal” if you are working on “Mac”.

To check GIT Version Installed

  • git –version

To initialize GIT Repository (Local Working Copy)

  • git init

Create a New File

  • touch abc.txt

To see GIT Status

  • git status

To add the file(s) in Staging Area

  • add *.*                   [It will add all files.]
  • add *.txt [It will add all text files.]
  • add *.html             [It will add all html files.]
  • add .                      [It will add each & everything to this folder.]

To add the file in Local Repository

  • git commit -m “Write message here”

Push the code to GitHub repository from local repository.

  • ·         git remote add origin
  • git remote -v [To verify the Remote]
  • ·         git push -u origin master

To see all changes

  • git log – To see all commits history (show 40 digits commit #)
  • git log –oneline  (To see one line commit detail)
  • git log –oneline -3 (To see three commits)

To upload one code folder to GitHub

Let’s the project code folder name is “Java Practice”

Create a folder at GitHub with “Java Practice”

To pull

Create local folder

  • git init                                                                    
  • git pull origin master          

In case of Merge

  • When another user commits something before your commit, then merge is required.
  • Then, run pull command:-
  • git pull origin master
  • It will show Merge window. Press i, enter the comment and then enter :wq!

Tag Commands

Create a new Tag

  • git tag ver1.0

To show all tags

  • git tag

Push Tag to Remote

  • git push origin ver1.0

Delete the tag

  • git tag -d ver1.0
  • git push origin -d ver1.0

Create Branch and Merge with Master

  • git branch branchname
  • git checkout branchname                 [Switch to Branch]
  • touch abc.txt                                         [Create a file]
  • git add .
  • git commit -m “by branchname”
  • git push -u origin branchname          [Push to server]

Note:- At GitHub, abc.txt file will not be shown under master branch, it will be shown only for deepakbranch.

Merge Branch to Master

  • git checkout master             [First move to Master]
  • git merge master 
  • git push -u origin master [Push changes to server]

Note:- At GitHub, now you can see abc.txt file in Master branch.


  • git rebase master

Delete Branch

  • git branch -d deepakbranch                              [From local]
  • git push origin –delete deepakbranch            [From server]

Note:- Now deepakbranch must be deleted from server.

To see the difference between master and current branch

  • git diff master

To Fetch all changes in Master

  • git fetch origin
  • Note:- git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring.

Other Commands

  • clear [To clear the screen]
  • i – To insert the comment
  • :wq! For save quit.
  • Ctrl + z : To come out from log screen.
  • mkdir : To create a directory
  • cd : to go respective folder.
  • ls – to see all folders and files
  • dir – to see all folders and files (Windows machine)
  • notepad index.html – Open Notepad
  • cat index.html – To view the file.

Please comment below if I missed any other important command(s).

Cheers! Deepak


Please enter your comment!
Please enter your name here