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 moving to it from subversion or you’re more intent on coding your project than learning git.
It is important to know how git works to be able to use it properly. Learn.github is a good place to start to learn the basics.
One you start using 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.
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 things listed here. These are just the commands I mostly use and 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;
# Pushing the changes
git push
# Meanwhile someone else made changes to the remote version
# Pulling those changes
git pull origin abc
# if you want to simply use 'git pull' to get the changes, do the following
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):
#to view the checksum of a commit, you can do
git log --pretty=oneline
git tag -a v1.0 98eda02
Push tags to remote repo:
Useful git references:
Learn.github
Github’s git cheat sheet
