My Git Cheat Sheet

I’ve been slowly adding to a cheat sheet I printed out a year ago. Half the commands I don’t use and the ones I use the most aren’t on there, so here’s mine…

Check out a new repo
git clone git://location/proj.git

Actually see what’s going on
gitk --all

Interactive adding for commits
git add -i

Unstage changes
git reset HEAD

Return to last committed state
git reset --hard

Undo a merge
git reset --hard [ID]
git reset --hard HEAD~[number back]

Undo a commit with message
git reset --soft HEAD^

Modify a commit
git commit --amend

Add more files to existing commit
git add ...
git commit --amend -C HEAD

Branches have diverged – just get up stream
git reset --hard @{upstream}

Checkout specific version of a file
git checkout [ID] [FILE]

Updating submodules
git submodule init
git submodule sync
git submodule update

Go through every submodule and checkout the head
git submodule foreach git checkout master
git submodule foreach git pull origin master
Or automatically merge
git submodule update --merge

Show difference between two branches
git diff [BRANCH 1]..[BRANCH 2]

Difference between two commits
git diff [ID1] [ID2]

Merge a branch back into master
git checkout master
git merge [BRANCH]

Show all branches
git branch --all

Checkout and track remote branch
git checkout -t [BRANCH]

Advertisements

One thought on “My Git Cheat Sheet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s