Git Cheat Sheet
Source Document
Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.
Setup
Configuring user information used across all local repositories
git config --global user.name "[firstname lastname]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
Setup & Init
Configuring user information, initializing and cloning repositories
git init
git clone [url]
Stage & Snapshot
Working with snapshots and the Git staging area
git status
git add [file]
git reset [file]
git diff
git diff --staged
git commit -m "[descriptive message]"
Branch & Merge
Isolating work in branches, changing context, and integrating changes
git branch
git branch [branch-name]
git checkout
git merge [branch]
git log
Share & Update
Retrieving updates from another repository and updating local repos
git remote add [alias] [url]
git fetch [alias]
git merge [alias]/[branch]
git push [alias] [branch]
git pull
Inspect & Compare
Examining logs, diffs and object information
git log
git log branchB..branchA
git log --follow [file]
git diff branchB...branchA
git show [SHA]
Tracking Path Changes
Versioning file removes and path changes
git rm [file]
git mv [existing-path] [new-path]
git log --stat -M
Rewrite History
Rewriting branches, updating commits and clearing history
git rebase [branch]
git reset --hard [commit]
Temporary Commits
Temporarily store modified, tracked files in order to change branches
git stash
git stash list
git stash pop
git stash drop
Ignoring Patterns
Preventing unintentional staging or committing of files
git config --global core.excludesfile [file]
Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs:
logs/
*.notes
pattern*/
Installation & GUIs
With platform specific installers for Git, GitHub also provides the ease of staying up-to-date with the latest releases of the command line tool while providing a graphical user interface for day-to-day interaction, review, and repository synchronization.
GitHub for Windows: https://windows.github.com
GitHub for Mac: https://mac.github.com
For Linux and Solaris platforms, the latest release is available on the official Git web site.
Git for All Platforms: http://git-scm.com