You are on page 1of 1

Git Cheat Sheet (left to right) Command Flow

by Jan Krüger <jk@jk.gs>, http://jan-krueger.net/git/


Based on work by Zack Rusin

create browse change revert update branch commit push


Basics
Use git help [command] if you're stuck. init status mark changes reset pull checkout commit push
log to be respected
clone checkout fetch branch format-patch
by commit:
master default devel branch blame revert merge
origin default upstream branch show
diff
add am
HEAD current branch
HEAD^ parent of HEAD
HEAD~4 great-great grandparent of HEAD
foo..bar from branch foo to branch bar

Create Publish
In Git, commit only respects changes that
have been marked explicitly with add.
Useful Tools Tracking Files
From existing files
git init git commit [-a] git archive git add files
git add .
(-a: add changed files Create release tarball git mv old new
automatically)
From existing repository git bisect git rm files
git format-patch origin git rm --cached files
git clone ~/old ~/new (create set of diffs) Binary search for defects
git cherry-pick (stop tracking but keep files in working dir)
git clone git://... git push remote
git clone ssh://... (push to origin or remote) Take single commit from elsewhere
git tag foo git fsck
(mark current version) Check tree
git gc
Compress metadata (performance) Structure Overview
View git rebase
Forward-port local changes to
remote branch
Local Repository
git status Update git remote add URL
git diff [oldid newid] Register a new remote repository
working dir
git log [-p] [file|dir] for this tree
git fetch (from def. upstream)
git blame file git stash
git fetch remote checkout to switch
git show id (meta data + diff) Temporarily set aside changes
git pull (= fetch & merge) commit
commit
git show id:file git tag
git am -3 patch.mbox (there's more to it)
git branch (shows list, * = current) git apply patch.diff Current Branch
git tag -l (shows list) gitk
Tk GUI for Git
Branch (in .git)
(in .git)

Revert Branch
In Git, revert usually describes a new
pull push
commit that undoes previous commits.
git checkout branch
(switch working dir to branch)
Conflicts
Use add to mark files as resolved.
git reset --hard (NO UNDO) git merge branch
(reset to last commit) (merge into current)
Remote repository (e.g. origin)
git branch branch git diff [--base]
git revert branch
(branch current) git diff --ours
git commit -a --amend Branch Branch
(replaces prev. commit) git checkout -b new other git diff --theirs
git checkout id file
(branch new from other and git log --merge
switch to it)
gitk --merge

You might also like