This cheat sheet is available in 25+ languages. Visit github.com/github/training-kit to access translations.
Merge Commands
Advanced operations for managing merges.Stash Commands
Temporarily store modified, tracked files to change branches without committing.Save to stash
Save to stash
Remove from stash
Remove from stash
Apply stashed changes
Apply stashed changes
Checkout Commands
Advanced operations for working with branches and restoring files.| Command | Description |
|---|---|
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 |
Patch Commands
Apply changes from patch files to your repository.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.Additional log formatting options
Additional log formatting options
You can customize the log output further with additional flags:Shows a graphical representation of all branchesCustom format showing hash, author, relative date, and subject
Quick Reference Table
| Category | Command | Description |
|---|---|---|
| Merge | git merge --abort | Abort current merge |
| Stash | git stash | Save changes to stash |
| Stash | git stash pop stash@{n} | Apply and remove stash |
| Stash | git stash apply stash@{n} | Apply stash (keep in list) |
| Restore | git restore . | Discard all changes |
| Restore | git restore --source=stash@{0} [file] | Restore file from stash |
| Switch | git switch -c [branch] | Create and switch to branch |
| Patch | git apply [patch file] | Apply patch file |
| Log | git log --pretty=oneline | One-line log format |