~/tools / Git Cheatsheet
Git Cheatsheet
A searchable quick reference for common git commands.
For those "what was that command again" moments — search by the command itself or by what you're trying to do (e.g. "undo", "stash"). Covers everything from the basics to branching and history rewrites.
# Use Cases
- You know what you want to do (undo the last commit) but can't recall the exact command
- Stashing your work-in-progress changes so you can switch branches
- Recalling the command to view only staged changes before a review
# Usage
- Type a command name (e.g. branch) or what you're trying to do (e.g. undo, stash) into the search box.
- Results are filtered by matching either the command or its description.
- Leave it blank to see the full list.
git initCreate a new Git repositorygit clone <url>Clone a remote repositorygit statusShow the working tree statusgit add .Stage all changesgit commit -m "message"Commit staged changesgit commit --amendAmend the previous commitgit push origin <branch>Push a branch to the remotegit pullFetch and merge changes from the remotegit fetchFetch remote changes without merginggit branchList branchesgit branch <name>Create a new branchgit checkout -b <name>Create and switch to a new branchgit switch <branch>Switch to a branchgit merge <branch>Merge a branch into the current onegit rebase <branch>Replay current changes on top of another branchgit log --onelineShow commit history, one line per commitgit diffShow unstaged changes in the working directorygit diff --stagedShow staged changesgit stashTemporarily shelve uncommitted changesgit stash popRestore the most recently stashed changesgit reset --soft HEAD~1Undo the last commit, keeping the changesgit reset --hard HEAD~1Undo the last commit and discard the changesgit revert <commit>Create a new commit that undoes a given commitgit tag <name>Tag the current commitgit remote -vList configured remotesgit cherry-pick <commit>Apply a single commit onto the current branch
# FAQ
- Is it safe to run these commands as-is?
- Some, especially git reset --hard and git push --force variants, can permanently lose changes or commit history. Understand what a command does before running it.
# Related
# Learn more on our sister sites
- Learn Git
Try the commands in a simulated terminal — prodou.net