Braindump

Git Survival Guide

I prefer to use Mercurial, but here is what I refer to when using git...

Basic day to day usage

Basic usage
git initCreate an empty repository in the current directory.
git clone URL fooCreate a repository in directory foo with the contents of the project at URL. This also sets the configuration option remote.origin.master as a convenience for future pulls.
git statusPrint information about the Git index (the staging area). List modified files in the index, files with modifications that have not been added to the index and untracked files.
git add [FILE | DIR]Add a file to the Git index or update the index with the current modifications.
git commitCommit the changes present in the index ('not' the working directory).
git commit -aCommit all changes present in the working directory (like Subversion does).
Diff
git diffShow changes in the working directory, not yet added to the index.
git diff --cachedShow changes added to the index.
git diff HEADShow all not comitted changes in the working directory.
git diff fooShow changes between the working directory and the tip of branch "foo".
Branching
git branchList all branches. An asterisk * marks the current branch.
git branch fooCreate branch "foo", based on the current branch.
git checkout fooSwitch to branch "foo".
git merge fooMerge changes on branch "foo" into current branch.
git branch -d fooSafely delete branch "foo". This ensures that the changes in branch foo are merged into the current branch.
git branch -D fooUnsafely delete branch "foo". I.e. force deletion even if the changes have not been merged. (Throw away a crazy idea)

Being picky about changes

Rebasing
git log foo..What changes were on branch foo since we branched?
git rebase fooStore all commits since the branch as patches, "fast forward" (special merge) to foo's tip and then re-apply the patches.
git rebase --continueIf there was a conflict, go on rebasing. (Similar to git commit -a for regular merges)
git rebase --abortStop rebasing and return your branch to before you started (e.g. if a conflict occured).
git rebase [-i|--interactive] fooInteractively select changes (aka 'cherry picking') from foo.
Interactive adding
git add -iInteractively stage or unstage (revert) files. It also (menu item "5: patch") allows to selectively stage only a part of a file ([patch] hunk by hunk) for committing (another form of 'cherry picking').
Stashing
git stash "WIP on feature X: Make it look better"Stores the changes on the "stash" and resets the working directory. This can be done more than once.
git stash applyRestore the previous working state by applying all stashed changes.
git stash listShow the list of stashed changes.
git stash apply stash@{1} Apply a specific stashed change.
git stash clearClear the stash.