Git CheatSheet
CheatSheet
SETUP
Configuring user information used across all local repositories
Set a name that is identifiable for credit when reviewing version history.
Set an email address that will be associated with each history marker.
Set automatic command line coloring for Git for easy reviewing.
SETUP & INIT
Configuring user information, initializing and cloning repositories
Initialize an existing directory as a Git repository.
Retrieve an entire repository from a hosted location via URL.
STAGE & SNAPSHOT
Working with snapshots and the Git staging area
Show modified files in the working directory, staged for your next commit.
Add a file as it looks now to your next commit (stage).
Unstage a file while retaining the changes in the working directory.
Diff of what is changed but not staged.
Diff of what is staged but not yet committed.
Commit your staged content as a new commit snapshot.
BRANCH & MERGE
Isolating work in branches, changing context, and integrating changes
List your branches. A *
will appear next to the currently active branch.
Create a new branch at the current commit.
Switch to another branch and check it out into your working directory.
Merge the specified branch’s history into the current one.
Show all commits in the current branch’s history.
SHARE & UPDATE
Retrieving updates from another repository and updating local repos
Add a git URL as an alias.
Fetch down all the branches from that Git remote.
Merge a remote branch into your current branch to bring it up to date.
Transmit local branch commits to the remote repository branch.
Fetch and merge any commits from the tracking remote branch.
TRACKING PATH CHANGES
Versioning file removes and path changes
Delete the file from the project and stage the removal for commit.
Change an existing file path and stage the move.
Show all commit logs with an indication of any paths that moved.
TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change branches
Save modified and staged changes.
List stack-order of stashed file changes.
Write working from the top of stash stack.
Discard the changes from the top of stash stack.
REWRITE HISTORY
Rewriting branches, updating commits, and clearing history
Apply any commits of the current branch ahead of the specified one.
Clear staging area, rewrite working tree from the specified commit.
INSPECT & COMPARE
Examining logs, diffs, and object information
Show the commit history for the currently active branch.
Show the commits on branchA that are not on branchB.
Show the commits that changed the file, even across renames.
Show the diff of what is in branchA that is not in branchB.
Show any object in Git in human-readable format.
IGNORING PATTERNS
Preventing unintentional staging or committing of files
Set a system-wide ignore pattern for all local repositories.
Create a .gitignore
file with patterns like:
This file will prevent unintentional staging or committing of files that match these patterns.
For more information and updates, visit: