Skip to main content
This advanced cheat sheet covers more sophisticated Git operations for users who are comfortable with the basics and need quick reference for advanced workflows.
This cheat sheet is available in 25+ languages. Visit github.com/github/training-kit to access translations.

Merge Commands

Advanced operations for managing merges.
git merge --abort
Abort the merge and return to the pre-merge state

Stash Commands

Temporarily store modified, tracked files to change branches without committing.
git stash save <stash name>
Save current changes to a stash with a particular name
git stash
Save current changes to a stash (saves it as stash@)
git stash drop
Drop the stash at the top of the stack
git stash drop stash@{n}
Drop the stash at the nth index
git stash pop stash@{n}
Apply the stash at the nth index and delete from the list
git stash apply stash@{n}
Apply the stash at the nth index (keeps it in the stash list)

Checkout Commands

Advanced operations for working with branches and restoring files.
CommandDescription
git restore .Discards all the changes in the working directory
git switch -c <branch name>Create a new branch and switch to that branch
git restore --source=<stash@{0}> <filename>Bring a single file to the working space from the stash
The git restore and git switch commands are modern alternatives to git checkout, providing clearer separation between switching branches and restoring files.

Patch Commands

Apply changes from patch files to your repository.
git apply <patch file>
Apply a patch file (.diff or .patch) to the repo
Patch files are useful for sharing changes without using a remote repository or when working with contributors who don’t have direct access to your repository.

Log Commands

Advanced log viewing for better readability and analysis.
git log --pretty=oneline
Prettify the log history of git, displaying each commit on a single line
You can customize the log output further with additional flags:
git log --oneline --graph --all
Shows a graphical representation of all branches
git log --pretty=format:"%h - %an, %ar : %s"
Custom format showing hash, author, relative date, and subject

Quick Reference Table

CategoryCommandDescription
Mergegit merge --abortAbort current merge
Stashgit stashSave changes to stash
Stashgit stash pop stash@{n}Apply and remove stash
Stashgit stash apply stash@{n}Apply stash (keep in list)
Restoregit restore .Discard all changes
Restoregit restore --source=stash@{0} [file]Restore file from stash
Switchgit switch -c [branch]Create and switch to branch
Patchgit apply [patch file]Apply patch file
Loggit log --pretty=onelineOne-line log format

Build docs developers (and LLMs) love