Braindump
					
					
					
      
      
				
			Git Survival Guide
Braindump.GitSurvivalGuide History
Hide minor edits - Show changes to markup
January 17, 2010, at 02:36 PM 
        by  - 
        Added lines 1-40:
        I prefer to use Mercurial, but here is what I refer to when using git...
Basic day to day usage
| Basic usage | |
|---|---|
git init | Create an empty repository in the current directory. | 
git clone URL foo | Create 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 status | Print 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 commit | Commit the changes present in the index ('not' the working directory). | 
git commit -a | Commit all changes present in the working directory (like Subversion does). | 
| Diff | |
git diff | Show changes in the working directory, not yet added to the index. | 
git diff --cached | Show changes added to the index. | 
git diff HEAD | Show all not comitted changes in the working directory. | 
git diff foo | Show changes between the working directory and the tip of branch "foo". | 
| Branching | |
git branch | List all branches. An asterisk * marks the current branch. | 
git branch foo | Create branch "foo", based on the current branch. | 
git checkout foo | Switch to branch "foo". | 
git merge foo | Merge changes on branch "foo" into current branch. | 
git branch -d foo | Safely delete branch "foo". This ensures that the changes in branch foo are merged into the current branch. | 
git branch -D foo | Unsafely 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 foo | Store all commits since the branch as patches, "fast forward" (special merge) to foo's tip and then re-apply the patches. | 
git rebase --continue | If there was a conflict, go on rebasing. (Similar to git commit -a for regular merges) | 
git rebase --abort | Stop rebasing and return your branch to before you started (e.g. if a conflict occured). | 
git rebase [-i|--interactive] foo | Interactively select changes (aka 'cherry picking') from foo. | 
| Interactive adding | |
git add -i | Interactively 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 apply | Restore the previous working state by applying all stashed changes. | 
git stash list | Show the list of stashed changes. | 
git stash apply stash@{1}  | Apply a specific stashed change. | 
git stash clear | Clear the stash. |