Home | Projects | Notes > Unix/Linux > Git Cheat Sheet
With platform specific installers for Git, Github also provides the ease of staying up-to-date with the latest release of the command line tool while providing a graphical user interface for day-to-day interaction, review, and repository synchronization.
For Linux and Solaris platforms, the latest release is available on the official Git web site.
Git for All Platforms: http://git-scm.com
Configuring user information used across all local repositories:
Set a name that is identifiable for credit when review version history
xxxxxxxxxx11git config --global user.name "<firstname lastname>"Set an email address that will be associated with each history marker
xxxxxxxxxx11git config --global user.email "<valid_email>"Set automatic command line coloring for Git for easy reviewing
xxxxxxxxxx11git config --global color.ui autoShow system, global, and (if inside a repository) local configs
xxxxxxxxxx11git config --listAlso shows the origin file of each config item
xxxxxxxxxx11git config --list --show-origin
Initialize an existing directory as a Git repository
xxxxxxxxxx11git initRetrieve an entire repository from a hosted location via URL
xxxxxxxxxx11git clone <url>
Working with snapshots and the Git staging area:
Show modified files in working directory, staged for your next commit
xxxxxxxxxx11git statusAdd a file as it looks now to your next commit (stage)
xxxxxxxxxx11git add <file>Unstage a file while retaining the changes in working directory
xxxxxxxxxx11git reset <file>diff of what is changed but not stanged
xxxxxxxxxx11git diffdiff of what is staged but not yet committed
xxxxxxxxxx11git diff --stagedCommit your staged content as a new commit snapshot
xxxxxxxxxx11git commit -m "<descriptive_message>"
Isolating work in branches, changing context, and integrating changes:
List your branches, a * will appear next to the currently active branch
xxxxxxxxxx11git branchCreate a new branch at the current commit
xxxxxxxxxx11git branch <branch_name>Switch to another branch and check it out into your working directory
xxxxxxxxxx11git checkoutMerge the specified branch's history into the current one
xxxxxxxxxx11git merge <branch>Show all commits in the current branch's history
xxxxxxxxxx11git log
Examining logs, diffs and object information:
Show the commit history for the currently active branch
xxxxxxxxxx11git logShow the commits on branchA that are not on branchB
xxxxxxxxxx11git log branchB..branchAShow the commits that changed file, even across renames
xxxxxxxxxx11git log --follow <file>Show the diff of what is in branchA that are not in branchB
xxxxxxxxxx11git diff branchB..branchAShow any object in Git in human-readable format
xxxxxxxxxx11git show <SHA>
Versioning file removes and path changes:
Delete the file from project and stage the removal for commit
xxxxxxxxxx11git rm <file>Change an existing file path and stage the move
xxxxxxxxxx11git mv <existing_path> <new_path>Show all commit logs with indication of any paths that moved
xxxxxxxxxx11git log --stat -M
Preventing unintentional staging or committing of files:
Add the name of the file or the path to the directory to ignore tracking in the .gitignore file
Retrieving updates from another repository and updating local repos:
Add a git URL as an alias
xxxxxxxxxx11git remote add <alias> <url>Fetch down all the branches from that Git remote
xxxxxxxxxx11git fetch <alias>After 'git fetch', 'git log' and 'git status' will show you the difference between origin/master(remote repository) and HEAD->master(local reposiory)
Merge a remote branch into your current branch to bring it up to date
xxxxxxxxxx11git merge <alias>/<branch>Transmit local branch commits to the remote repository branch
xxxxxxxxxx11git push <alias> <branch>Fetch and merge any commits from the tracking remote branch
xxxxxxxxxx11git pull
Rewriting branches, updating commits and clearing history:
apply any commits of current branch ahead of specified one
xxxxxxxxxx11git rebase <branch>clear staging area, rewrite working tree from specified commit
xxxxxxxxxx11git reset --hard <commit>
Temporarily store modified, tracked files in order to change branches:
save modified and staged changes
xxxxxxxxxx11git stashlist stack-order of stashed file changes
xxxxxxxxxx11git stash listwrite working from top of stash stack
xxxxxxxxxx11git stash popdiscard the changes from top of stash stack
xxxxxxxxxx11git stash drop