Git Cheat Sheet

This page gives you ready to use git commands which developer don’t remember every time. In this git cheat sheet, we included all git commands. Git is an open-source distributed version control system which gives efficiency and speed of creating versions and save code in a remote place for small or big projects. In this git cheat sheet, we created, git commands list with a short description. In this cheat sheet, we included from basic commands like git init, git clone, git pull, git push, git commit, git rebase to advance commands like git clean, git stash, git reset

Git Cheat sheet
Git Cheat sheet

Git Configuration:

$ git config --global "your_name"

Set the user name in the git commit and tags.

$ git config --global "your_email"

Set the user email in the git commit and tags.

$ git config --local "your_name"
$ git config --local "your_email"

If you want to change the user details for any specific project, you will use above command.

Getting Git in the Project:

$ git init

To convert a project directory into a git repository, we need to run above command.

$ git clone "url"

Get the git project from remote repo, we need to run git clone with url argument.

Git Branching:

Get list of all git branches:

// list all branches
$ git branch

Create New Branch:

// create new branch
$ git branch branch_name

Delete Branch

// delete the branch
$ git branch -d branch_name

Delete Remote Branch

// delete the remote branch
$ git push origin --delete branch name

Git Checkout:

// switch to another branch and checking it out in directory
$ git checkout branch_name

// create new branch and checking it out 
$ git checkout -b branch_name

// switch to previous branch
$ git checkout -

Git Merging

Merge into Active Branch:

// merge into active branch
$ git merge branch name

Merge into Target Branch:

// merge into target branch
$ git merge source_branch_name target_branch_name

Git Stashing:

List out All Stashes:

// list out all current stashes
$ git stash list

Create New Stash:

// create new stash (both commands gives you same result, msg is optional)
$ git stash [msg]
$ git stash push [msg]

Remove Stash:

// apply changes from latest stash and remove latest stash
$ git stash pop

$ git stash apply [stash_id]

Apply changes from the specified stash in working directory. if stash_id is not given, latest stash will apply.

Show Stash Changes:

$ git stash show [stash_id]

show the changes as diff between stash changes and current code. If stash_id is not given, then latest stash will apply.

Clear All Stashes:

Remove all stashes from stash list.

$ git stash clear

Git Snapshot:

Git status:

$ git status

Add a file:

// add a file in staging
$ git add file.txt

Add all files:

// add all files in staging
$ git add -a
$ git add .

Git Commit:

$ git commit -m "commit_message"

Git Synchronization:

Push Branch To Remote:

$ git push origin branch-name

Push Changes To Remote:

$ git push -u origin branch-name

Delete Remote Branch:

$ git push origin --delete branch-name

Git Pull:

$ git pull

Pull Changes From Remote:

$ git pull origin branch-name

Add a Remote Repository:

$ git remote add origin ssh://

Add SSH to Remote Repo

Add ssh to remote repository of git.

$ git remote set-url origin ssh://


Above is the full guide of Git Commands. Git is very helpful for versioning the project and remembering all git commands is impossible. That’s why I listed out all Git commands in this Git Cheat Sheet. Above I listed out common git commands as git merge, git commit, git push, git pull, git stash, git branch to git configuration.

Please refer to all developer cheat sheet by following this link. If you have any doubt, please connect with me by email: