git Cheatsheet
When you’re new to git, it can get difficult to wrap your head around it at first. This is especially true if you’re migrating from subversion or when you’d rather spend more time writing your code than trying to learn git.
Git requires some learning, and you might as well spend the time doing it rather than wondering what just happened after running a command. Learn.github is a good place to start to learn the basics.
But even after spending some time learning git, there are going to be times that you’ve to painfully search the web/manual for basic stuff like working with remote branches or more complex stuff like handling a failed merge.
For the same reason, I’m creating this post as a reference point for myself to avoid repetitive searches. I’ll keep adding new commands here if and when I use them.
This is no way near to a complete reference for git and there might be better ways to do the things listed here. These are just the commands I use the most, in the manner I prefer to use them.
Basics
Commit & Stage all changes:
Push Changes to remote repo:
Pull Changes to local repo:
Check current status of working tree:
View diff:
Discard local uncommitted changes to a file (in this case, abc.txt):
Branches (Branch name is assumed to be ‘abc’)
Working with local branches
Create a branch:
Switch to a branch:
View all existing branches:
Remove a branch:
Merge a branch :
git checkout master
git merge abc
Working with remote branches
Push a local branch to remote repo:
Delete a remote branch:
Setup a local branch to track a remote branch:
Create a local branch, push it to remote repo. and then pull changes from it:
git checkout -b abc;
git push
# Meanwhile someone else made changes to the remote version
# Pulling those changes
git pull origin abc
git config branch.abc.remote origin
git config branch.abc.merge refs/heads/abc
Alternative methods listed here.
Tags (Tag name is assumed to be v1.0 here)
View all tags:
Create a tag referencing a particular commit using its checksum (annotated):
git log --pretty=oneline
Push tags to remote repo:
Useful git references:
Learn.github
Github’s git cheat sheet

