image/svg+xml
Git Cheat Sheet
Back – Command Quick Reference
This is version 2.0 of Jan Krüger's Git cheat sheet. You can contact the author by e-mail at: <jk@jk.gs>.Partially based on work by Zack Rusin, http://zrusin.blogspot.com/
Create
From existing files git init git add . git commitFrom remote repository git clone .../old .../new git clone git://... git clone ssh://...
Browse
git statusgit diff oldref newrefgit log [-p] [file|dir]git blame filegit show ref[:file]git branch (shows list, * = current)git tag -l (shows list)
Track Files
git add filesgit mv old newgit rm filesgit rm --cached files (stop tracking but keep files in working dir)
Revert
In Git, reverting usually means adding a committhat undos changes in previous commits.git reset --hard (NO UNDO) (throw away all pending changes)git revert refgit commit -a --amend (replace previous commit)git checkout ref file
Object refs
master default devel branchorigin default upstream branchHEAD current branchHEAD^ parent of HEADHEAD~4 great-great grandp. of HEADfoo..bar from ref foo to ref bar
Change
Update
git fetch (from default upstream)git fetch refgit pull (= fetch + merge)git am -3 patch.mboxgit apply patch.diff
Record
In Git, commit only respects changes that havebeen marked explicitly with add.git commit [-a] (-a: add changed files automatically)git push [remote] (push to origin or remote)git tag foo (mark current version)
Branch
git checkout branch (switch working dir to branch)git merge branch (merge into current)git branch branch (branch current)git checkout -b new other (branch new from other and switch to it)
Publish
git pushgit push remotegit format-patch origin (create set of diffs)
Resolve Conflicts
Use add to mark files as resolved.git diff [--base]git diff --oursgit diff --theirsgit log --mergegitk --merge
Other Useful Commands
git archive Create release tarballgit bisect Binary search for defectsgit cherry-pick Take single commit from elsewheregit fsck Check treegit gc Compress metadata (performance)git rebase Forward-port local changes to remote branchgit remote add URL Register a new remote repository for this treegit stash Temporarily set aside changesgit tag (there's more to it)
Explanation of Syntax[foo] foo is optional... You can get creative herefoo foo is a placeholder for something you need to fill inref An object hash or name (see "Object Refs" for standard names)
Configuration
Change options using git config [--global] varname value. The following variable names are useful:core.bare True for repositories without a working tree (usually public repositories).core.sharedRepository Set to group or all to make the repository contents writeable for the file group or everybody.core.compression A zlib compression level for objects (0-9, 9 = best compression) or -1 to use zlib's default.color.branch Color-code list of branches (true = always, auto = only when outputting to a terminal)color.diff Color-code diffs (true, auto)color.status Color-code output of git status (true, auto).user.email Your e-mail address (used in commits).user.name Your name (used in commits).
Commit Messages
Some of Git's viewing tools need com-mit messages in the following format:A brief one-line summary<blank line>Details about the commit
There's a little bit of room for your own notes here. This is your chance to customize this cheat sheet!