Not another git cheatsheet you say?? There are a ton of git cheatsheets already. It is highly unlikely that i’ll ever refer to a cheat sheet when I can just google that sh** in 5 min and go through 5 Stack Overflow answers. Copy-paste random things until something works!
Show me the good stuff
Why another Git Cheatsheet?
I beg to differ. I say this because most of the git cheat-sheets out there are very generic and have commands that I will rarely use. In my 4 years of dev career, which is pretty small as compared to some of the veterans out there, but still have managed to narrow down to the following git commands.
These are the commands that I use daily, almost. Some of these are the ones that come handy when I f*** up and f*** up bad. Some of these are just because I am too lazy to type.
Why a blog? Why a publicly available blog?
This is majorly a self-note blog post. A reference point for me. No matter where I am, and irrespective of the organisation I am working for, this blog post will be the go-to point.
What’s in it for you?
Nothing special, but might also be everything you want. To be honest, bookmark it, or ignore it if you feel it’s too much. But the following are the commands that I have used and I am positive that I’ll be using it in near future!

GIT commands
I want to | Command |
---|---|
Delete a branch locally | git branch -d localBranchName |
Delete a branch remotely | git push origin --delete remoteBranchName |
Delete a branch locally and remotely | git branch -d localBranchName && git push origin --delete remoteBranchName |
Check the remote of repo with url | git config --get remote.origin.url |
Change author of last commit | git commit --amend --author="Author Name email@address.com" :w :q |
Delete tag on remote | git push --delete origin tagname |
Delete tag locally | git tag --delete tagname |
Delete a remote | git remote rm remoteName |
Squash (N is the number of commits) | git reset HEAD~N Reference 1 |
Delete a stash by stash number | git stash drop stash@{n} |
Delete all unstaged files | git checkout . git reset --hard HEAD |
Unstage all staged files | git reset |
Revert last merge | git reset --hard HEAD~1 |
Reset and sync local repository with remote branch | git fetch origin && git reset --hard origin/master && git clean -f -d Reference 1 |
Show only last N number of commits | git log --oneline -N |
Remove all unstagged changes | git checkout -- . |
Remove git from a repo | rm -rf .git* |
Merge without merge commit | Reference 1 |
Revert last pushed commit | git revert commitHash |
Rename branch | git branch -m newName |
Check if a branch contains a particular commit | git branch --contains | grep commitHash | grep branchName |
Useful GIT resources
ReadMe and Markdown
Git Alias

Git Alias are nothing but git
shortcuts. For example:
cp = cherry-pick
st = status -s
cl = clone
ci = commit
co = checkout
br = branch
diff = diff --word-diff
dc = diff --cached
A progammer uses simple commands like fetch, pull, merge, rebase, push on a daily basis and like a 1000 times. There are commands that are simple, yet verbose to type. Git Alias helps to create shortcuts for these git scripts.
You can add alias one at a time:
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
or you can add them all at once. To setup git alias, we need to edit the .gitconfig
file and add the aliases there. The path of this file can vary depending on the operating system you are working on.
Generally,
- MacOS:
~/.gitconfig
- Linux:
~/.gitconfig
- Windows: It can be different based on system settings. A starting point
To quickly open, try running git config --global --edit
in terminal and it is highly possible that it will open in your default editor.
There are literally a ton of aliases that you can use and what works for me, might not work for you. Thus, will drop few links here, wherein you can select the aliases that works for you.
- Must Have Git Aliases: Advanced Examples by Nicola Paolucci
- Sample
.gitconfig
file: Check here or here
The most powerful feature of git alias is positional parameters. Positional parameters, in simple words are the values to your alias functions. Yes, functions.
my_alias = "!f() { 〈your complex command〉 }; f"
You can write alias functions that take arguments (just like normal functions) and run the script with them. The only thing you have to take care of is the order in which you pass parameters while invoking alias.
- $1 to mean the first parameter passed to the command.
- $2 to mean the second parameter passed to the command. (and so on for $3,
$4, etc.)
For example, if you want to delete branch locally and remotely but don’t want to remember the long git script
git branch -d localBranchName && git push origin --delete remoteBranchName
You can create a git alias function
delAll = "!f() { \
git branch -D $1 && git push origin --delete $1; \
}; f"
Now, all you have to do is pass the branch name you want to delete locally and on remote. You can fire this beauty by:
git delall mybranchName