Git Commands Cheat Sheet

In this post we will be seeing Git Commands, Git is open source distributed version controlled system. This Git Commands Cheat Sheet consists of most important and widely used Git Commands.

So let’s get started,

Windows: Use Chocolatey and in powershell type

choco install git


ubuntu: sudo apt-get update && sudo apt-get install git -

redhat: sudo yum install git 

Mac OS:

install Homebrew and Xcode

Set a user name which can be seen or associated with every commit

git config --global "nuclear geeks"

Set a user email which can we seen or associated with every commit

git config --global ""

Clone an existing repository

git clone url

Check the modified file in working directory.

git status

Add a modified file to staging area.

git add <file_name>

Add all the modified file to staging area

git add . 

Commit message

git commit -m "commit_message"

Difference between working area and staging

git diff <file_name>

Difference between working area and last commit or repository

git diff origin/branch filename

Difference between staging area and repository

git diff --staged 
git diff --staged <file_name>

List all your branches

git branch 

Create new branch

git checkout -b <branch_name>

Push the branch to origin

git push origin <branch_name>

Switch to another branch

git checkout <branch_name>

Merge branches

git merge <branch_name>

Backout File, If you want to move your file from stage area to working or unstage area

git reset HEAD <file_name>

Discard changes in working directory

git checkout <file_name>

Delete file

git rm <file_name>

Rename a file

git mv <current_name> <new_name>

Move a file

git mv <file_name> <dir_name>

Git alias, renaming command to new name

git config -global alias. <short_command> <"long command">

Find hidden file

git ls -al 

Stash your changes

git stash

To apply your changed from stash

git stash apply

To delete your stash from the list

git stash drop

To list your stash list

git stash list 

To apply the changes and delete from the listt

git stash pop

Git stash with message

git stash save "msg"

Find change done in specific index

git stash show stash@{id}


git stash apply stash@{id}

Tag creation

git tag <tag_name>

Annotated tag creation

git tag -a <tag_name>

Push tag to remote

git push origin <tag_name>

List all the tags

git tag --list

Delete tags

git tag --delete <tag_name>

Create a branch from the tag

git checkout -b <branch_name> <tagname>

Create a tag from past commit

git tag <tag_name> <reference_of_commit>

So I’ve tried to covered almost all the commands used, do reply in the comment section if you have any trouble with any of the above commands.

Categories: DevOps, GIT

Tags: , , ,

Leave a Reply

Please log in using one of these methods to post your comment: 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

<span>%d</span> bloggers like this: