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
xxxxxxxxxx
11git config --global user.name "<firstname lastname>"
Set an email address that will be associated with each history marker
xxxxxxxxxx
11git config --global user.email "<valid_email>"
Set automatic command line coloring for Git for easy reviewing
xxxxxxxxxx
11git config --global color.ui auto
Show system, global, and (if inside a repository) local configs
xxxxxxxxxx
11git config --list
Also shows the origin file of each config item
xxxxxxxxxx
11git config --list --show-origin
Initialize an existing directory as a Git repository
xxxxxxxxxx
11git init
Retrieve an entire repository from a hosted location via URL
xxxxxxxxxx
11git clone <url>
Working with snapshots and the Git staging area:
Show modified files in working directory, staged for your next commit
xxxxxxxxxx
11git status
Add a file as it looks now to your next commit (stage)
xxxxxxxxxx
11git add <file>
Unstage a file while retaining the changes in working directory
xxxxxxxxxx
11git reset <file>
diff
of what is changed but not stanged
xxxxxxxxxx
11git diff
diff
of what is staged but not yet committed
xxxxxxxxxx
11git diff --staged
Commit your staged content as a new commit snapshot
xxxxxxxxxx
11git 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
xxxxxxxxxx
11git branch
Create a new branch at the current commit
xxxxxxxxxx
11git branch <branch_name>
Switch to another branch and check it out into your working directory
xxxxxxxxxx
11git checkout
Merge the specified branch's history into the current one
xxxxxxxxxx
11git merge <branch>
Show all commits in the current branch's history
xxxxxxxxxx
11git log
Examining logs, diffs and object information:
Show the commit history for the currently active branch
xxxxxxxxxx
11git log
Show the commits on branchA
that are not on branchB
xxxxxxxxxx
11git log branchB..branchA
Show the commits that changed file, even across renames
xxxxxxxxxx
11git log --follow <file>
Show the diff
of what is in branchA
that are not in branchB
xxxxxxxxxx
11git diff branchB..branchA
Show any object in Git in human-readable format
xxxxxxxxxx
11git show <SHA>
Versioning file removes and path changes:
Delete the file from project and stage the removal for commit
xxxxxxxxxx
11git rm <file>
Change an existing file path and stage the move
xxxxxxxxxx
11git mv <existing_path> <new_path>
Show all commit logs with indication of any paths that moved
xxxxxxxxxx
11git 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
xxxxxxxxxx
11git remote add <alias> <url>
Fetch down all the branches from that Git remote
xxxxxxxxxx
11git 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
xxxxxxxxxx
11git merge <alias>/<branch>
Transmit local branch commits to the remote repository branch
xxxxxxxxxx
11git push <alias> <branch>
Fetch and merge any commits from the tracking remote branch
xxxxxxxxxx
11git pull
Rewriting branches, updating commits and clearing history:
apply any commits of current branch ahead of specified one
xxxxxxxxxx
11git rebase <branch>
clear staging area, rewrite working tree from specified commit
xxxxxxxxxx
11git reset --hard <commit>
Temporarily store modified, tracked files in order to change branches:
save modified and staged changes
xxxxxxxxxx
11git stash
list stack-order of stashed file changes
xxxxxxxxxx
11git stash list
write working from top of stash stack
xxxxxxxxxx
11git stash pop
discard the changes from top of stash stack
xxxxxxxxxx
11git stash drop