Commonly used Git Commands

To set Visual Studio Code as Core Editor for Git. This command requires “code –wait” command working from command prompt, if not, then you may Add code to PATH environment variable and check the “code –wait” command working from command prompt OR you may replace “code” by actual path to code.exe

git config --global core.editor "code --wait"

Once above command is run, you can edit Git config in Visual Studio Code with below command

git config --global -e

Open global config with Visual Studio Code with above command and paste below lines in opened .gitconfig file which will set Visual Studio Code to be used as default tool for git difftool command

    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE

To check graphical view of commit history. Press ‘q’ to exit

git log --oneline --graph

Use below command to compare all the files in version before last commit and last commit, make sure you have set Visual Studio Code as default tool as mentioned above:

git difftool HEAD^ HEAD

To create new branch called feature

git branch feature
git checkout feature


git checkout -b feature

To merge above created feature branch to master

git add --all
git commit -m "commit message"
git checkout master
git merge feature

To pull changes from remote repo to local master branch and rebase master branch on the changes in remote repo.

git checkout master
git pull --rebase

To revert changes to specific unstaged file

git checkout -q -- <path_of_file>

To see difference between two files

git diff <path_of_file1_tobecompared> <path_of_file2_tobecompared>

To add untracked changes to changes to commit stage

git add --all

To check status of current commits, added changes etc.

git status

To check commit history

git log --oneline --graph

To push changes on master branch to remote repo named origin. Flag -u should be used only when you are pushing local branch to remote branch for the first time.

git push -u origin master

Sponsored Links

Published by Amol

Amol Awasare aka 'Sam' is highly passionate SharePoint Consultant who has extensively worked on various SharePoint editions starting with MOSS 2007, SP 2010, SP 2013, SP Online. Amol has started this blog to share his knowledge and connect with like minded people to explore SharePoint in all aspects.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website at
Get started
%d bloggers like this: