git initInitialize repogit clone <url>Clone repositorygit config --global user.name "Name"Set user.namegit config --global user.email "e@x.com"Set user.emailgit statusShow statusgit log --oneline --graphPretty historygit diffUnstaged changesgit diff --stagedStaged changesgit show <commit>Show commitgit add <path>Stage filegit add -pStage by hunkgit commit -m "msg"Commit stagedgit commit --amendEdit last commitgit reset <file>Unstagegit restore <file>Discard local changesgit branchList branchesgit switch <name>Switch branchgit switch -c <name>Create & switch branchgit merge <branch>Merge into currentgit rebase <branch>Rebase onto targetgit branch -d <name>Delete branch (safe)git branch -D <name>Force-delete branchgit remote -vList remotesgit remote add origin <url>Add a remotegit push -u origin mainPush & trackgit pull --rebasePull with rebasegit fetch --all --pruneFetch all remotesgit reset --soft HEAD~1Undo last (keep changes)git reset --hard HEAD~1Undo last commit (discard changes)git revert <commit>Safe revertgit stashStash uncommittedgit stash popPop stashgit reflogRecovery log (reflog)About Git Cheatsheet
In daily Git use, the flags for rebase, stash, and reset and the steps to recover commits via reflog are hard to remember, and searching mid-task breaks your flow. This tool is a categorized Git command cheat sheet covering high-frequency scenarios — committing, branching, merging, undoing, remote sync, and stashing — each with an explanation and typical usage. It renders locally with the page, no network needed, so you can glance at it beside your terminal. Undo commands fall into three scopes and understanding that ladder matters more than memorising the commands. Changing only working files, changing working files and the staging area, and rolling back to a specific commit widen the blast radius in turn, and a wider rollback more easily touches commits others have already pulled. Ask which layer you mean to undo before running anything, which stops most mistakes. Choosing merge or rebase depends on whether the branch is shared. Rebasing rearranges commits into a straight line that reads cleanly but rewrites identifiers, so rebasing a branch already pushed and pulled makes others fetch duplicated or broken history; merging keeps the fork point, slightly messier but fully traceable. Rebase local unshared branches and merge public ones. The reflog is the last resort and deserves remembering on its own. Most commits presumed lost are still recorded there and recoverable unless an automatic cleanup has run. On a wrong rollback or reset, check the log first rather than stacking more commands on top; stopping earlier improves recovery odds. How you resolve conflicts decides whether the same conflict keeps returning. Resolving each hunk by hand removes the divergence, but a conflict that repeats in one place usually means both sides changed the same logic, where aligning on the design first is more sensible than resolving it your own way each time. Treat conflicts as signals rather than obstacles. Commit message discipline bears directly on traceability. A message explaining why a change was made is worth far more months later than one naming a file, and mixing unrelated changes into one commit turns a rollback into a dissection job. Keep commits single-purpose and state the motivation, which makes a memo genuinely useful rather than merely tidy. Finally, a memo is bounded by version differences and is no universal table. Parameters and defaults for the same operation can change between releases, and release notes are the most direct place to find such differences. When a memo command fails, check the version docs rather than retrying the old syntax, or you will burn time down the wrong path.
How It Works Internally
A command cheat sheet is most valuable for remembering which operations are irreversible. Three are routinely misused: resetting to a commit and discarding the working tree (unrecoverable and not recorded in the reflog), rewriting history (changes commit identity and diverges everyone else branch when pushed), and a file-level checkout revert (overwrites current edits and is likewise absent from the reflog).
reset --soft / --mixed / --hard--soft keeps changes staged | --mixed keeps them in the working tree | --hard discards them with no reflog entry and no recoveryMeasured on This Page
| Commands and flags real | Git accepted the syntax of all 33 entries — no misspelled subcommand and no invented flag |
|---|---|
| 5 state dependencies | commit -m needs staged content, commit --amend wants an editor or prior commit, switch <name> requires an existing branch, branch -d/-D refuses the current branch, stash pop needs a stash, revert wants a clean tree, and remote add origin fails when the remote exists — all failures came from prior state, not bad syntax |
| Destructive commands | --hard, -D and reset sit alongside safe commands without visual distinction (flagged in the note) |
| Copy and search | Every command copies in one click and the search box filters by command or description |
What a cheat sheet owes the reader is not correctness — that is the floor — but the preconditions. All 33 entries here are genuine, yet 7 of them fail outright in the wrong state: stash pop with nothing stashed, branch -d against the current branch, switch <name> before the branch exists. Beginners stall exactly there, because the error text never says 'you missed a step'. Note too that reset --hard and branch -D destroy work immediately; stash first or confirm everything is pushed.
How to Use
- Open "Git Cheatsheet"
- Type an action or command into the filter box, such as rebase or stash
- Browse entries grouped by config, branch, commit and collaboration
- Open an entry to read its flags and undo warnings
- Click "Copy" and paste the command into the terminal
Use Cases
- Undo actions — Quickly check the difference between reset, revert, and checkout to safely roll back mistakes.
- Branch management — Reference create, switch, delete, and merge commands to clarify your branching workflow.
- Recover commits — Use reflog-related commands to recover commits lost to a reset or accidental deletion.
- Stash changes — Look up stash save, list, and restore usage to switch tasks without losing your working tree.
- Team standard — Use the cheat sheet as a shared Git reference to reduce mistakes across the team.
- Interactive rebase — Check the squash and reword flags for interactive rebase to clean up commit history.
- Cherry-pick flow — Look up the correct syntax to cherry-pick a range of commits between branches.
FAQ
What is the difference between reset soft, mixed, and hard?
soft moves HEAD but keeps the index and working tree; mixed (default) resets the index but keeps changes; hard discards working-tree changes too, so confirm before using it.
Should I use revert or reset?
For commits already pushed, prefer revert — it adds an inverse commit without rewriting history; reset rewrites history and suits local, unshared commits.
Does rebase lose commits?
A normal rebase does not lose commits but rewrites their hashes; if something goes wrong, use reflog to recover the previous HEAD.
Do these commands work on Windows?
Yes. The commands themselves are cross-platform; differences are mainly in the shell, and they work in Git Bash and PowerShell.
How do I write better commit messages?
The cheat sheet helps with commands; for well-structured commit messages, follow the Conventional Commits style and pair it with our related tools.
git reset --hard or git revert — which one?
Use revert for commits already pushed (it creates an inverse commit and is traceable); use reset --hard only for local unpushed commits. Running reset --hard on a shared branch and force-pushing scrambles collaborators' history — a classic team incident.
git pull or git fetch — what is the difference?
fetch downloads remote updates into the remote-tracking refs (origin/main) without touching your working tree; pull is fetch plus merge, which can create conflicts or surprise merge commits. Make a habit of fetching first and deciding how to integrate afterwards.
I lost my git stash — how do I recover it?
A stash is not truly gone until dropped: check git stash list for the stack, and dropped entries can be found as dangling commits via git fsck --lost-found then cherry-picked. Describe your stashes (git stash push -m) so the stack stays readable.