🌿Git Command Cheat Sheet - Undo, Branch, Rebase, Stash
Git is hard not because there are many commands but because the thing you want rarely matches the command name: to undo the last commit, is it reset, revert or restore? So this sheet is grouped by situation — undo and recovery, everyday commits, branches and rebase, remotes, investigating history, stashing, cleanup, configuration. Each entry says what it does and whether it throws work away.
Free · No sign-up · Runs in your browserLast updated:
Loading tool...
How to use Git commands
- 1Search by situation (undo, force push) or by command (rebase)
- 2Browse by group — start with undo and recovery
- 3Click a command to copy it, then replace anything in angle brackets
FAQ
- Which command actually undoes a commit?
- Not pushed yet: git reset --soft HEAD~1 keeps the changes staged. Already pushed and others may have pulled: git revert <commit> adds an inverse commit without rewriting history. Just want to drop a file's changes: git restore <file>.
- I reset away a commit — can I get it back?
- Almost always. git reflog lists every move of HEAD (kept for 90 days); find the SHA and run git reset --hard <sha> or git switch -c rescue <sha>. The objects are still there unless you ran git gc --prune=now.
- Merge or rebase?
- Merge into shared branches to keep the real history; rebase your own feature branch onto the trunk for a linear story. One rule: never rebase commits other people have already pulled.
- What is the difference between --force and --force-with-lease?
- --force overwrites the remote branch unconditionally, so a colleague's fresh commits vanish. --force-with-lease first checks the remote is still where you last saw it and refuses otherwise. Make the second one your habit.