Git Cheat Sheet

ADVERTISEMENT

Git Cheat Sheet
Command Flow
(left to right)
by Jan Krüger <jk@jk.gs>,
Based on work by Zack Rusin
create
browse
change
revert
update
branch
commit
push
Basics
init
status
mark changes
reset
pull
checkout
commit
push
Use git help [command] if you're stuck.
to be respected
log
clone
checkout
fetch
branch
format-patch
by commit:
blame
master
default devel branch
revert
merge
show
origin
default upstream branch
add
am
diff
HEAD
current branch
HEAD^
parent of HEAD
HEAD~4
great-great grandparent of HEAD
foo..bar
from branch foo to branch bar
Publish
Create
Useful Tools
Tracking Files
In Git, commit only respects changes that
have been marked explicitly with add.
From existing files
git add files
git commit [-a]
git archive
git init
git mv old new
(-a: add changed files
git add .
Create release tarball
automatically)
git rm files
git bisect
From existing repository
git format-patch origin
git rm --cached files
git clone ~/old ~/new
Binary search for defects
(create set of diffs)
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
Structure Overview
Compress metadata (performance)
View
git rebase
Local Repository
Forward-port local changes to
remote branch
Update
git remote add URL
git status
git diff [oldid newid]
working dir
Register a new remote repository
for this tree
git log [-p] [file|dir]
git fetch
(from def. upstream)
git stash
git blame file
checkout to switch
git fetch remote
Temporarily set aside changes
git show id
(meta data + diff)
git pull
(= fetch & merge)
git tag
commit
commit
git show id:file
git am -3 patch.mbox
(there's more to it)
Current
Branch
git branch
(shows list, * = current)
git apply patch.diff
gitk
git tag -l
Branch
(in .git)
(shows list)
Tk GUI for Git
(in .git)
Branch
Revert
In Git, revert usually describes a new
pull
push
Conflicts
commit that undoes previous commits.
git checkout branch
(switch working dir to branch)
Use add to mark files as resolved.
git reset --hard (NO UNDO)
git merge branch
Remote repository (e.g. origin)
(merge into current)
(reset to last commit)
git diff [--base]
git branch branch
git revert branch
git diff --ours
(branch current)
git commit -a --amend
Branch
Branch
git diff --theirs
git checkout -b new other
(replaces prev. commit)
git log --merge
(branch new from other and
git checkout id file
switch to it)
gitk --merge

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go