The Git Commands Worth Memorizing (And the Ones You Shouldn't)
Git has a few hundred commands and most developers use about fifteen of them regularly. The other few hundred get looked up exactly once, in a moment of panic, usually at the worst possible time, which is why it's worth knowing which commands are safe to run from memory and which ones deserve a second look first.
This covers the mental model that makes git commands make sense instead of feeling arbitrary, the small set of commands that cover most days, and the difference between commands that just inspect history and the ones that can actually lose work.
The Mental Model Behind Every Git Command
Git tracks three things: commits, which are snapshots of your project at a point in time; branches, which are movable pointers to a commit; and a staging area, a holding zone for changes before they become part of a commit. Almost every confusing command makes more sense once you ask which of those three things it's actually touching. A command that moves a branch is just repointing a label. A command that rewrites history is creating new commits and abandoning old ones.
The Handful of Commands That Cover Most Days
In practice, most day-to-day git work is some combination of checking status, staging changes, committing, pulling, pushing, and switching branches. Everything else, the merge conflict resolution, the rebase, the cherry-pick, comes up rarely enough that looking it up each time is completely normal, not a sign you don't know git.
Amend, Reset, and Revert Are Not the Same Thing
These three get confused constantly because they all sound like undo, but they do different things. Amend changes the most recent commit, replacing it with a new version. Reset moves a branch pointer backward, and depending on the mode, can discard changes entirely. Revert creates a brand-new commit that undoes a previous one, leaving history intact. If you only remember one distinction: amend and reset rewrite history, revert adds to it.
Knowing Which Commands Are Safe to Run Blind
Commands that only read information, checking status, viewing logs, diffing changes, are safe to run without thinking twice. Commands that discard or overwrite anything, a hard reset, a forced checkout, a forced push, deserve a pause and a second look at exactly what's about to happen, especially if anyone else has already pulled the branch you're about to rewrite.
Common Git Mistakes (And How to Undo Them)
- ✓Committing to the wrong branch, usually fixable by moving the commit to the correct branch and resetting the wrong one
- ✓Force-pushing over a branch someone else is also working on, overwriting their commits
- ✓Running a hard reset before realizing the changes weren't actually saved anywhere else
- ✓Amending a commit that's already been pushed and shared, which rewrites history other people now have a stale copy of
Letting a Helper Translate Plain English to Commands
A git command helper is useful exactly where the panic usually sets in: describe what you're trying to do in plain English and get back the actual command, plus an explanation of what it does before you run it. That explanation matters more than the command itself for anything destructive, since understanding the blast radius is the whole point. For the complete picture beyond any one command, the official Git documentation at https://git-scm.com/docs covers every flag and edge case the helper won't go into.
If the thing you're trying to untangle is less about the git command and more about understanding code you're looking at in an unfamiliar branch, our code explainer covers that side of it.
Frequently Asked Questions
What's the difference between git reset and git revert?▼
Reset moves your branch pointer backward and can discard changes, rewriting history. Revert creates a new commit that undoes a previous one, leaving the original history intact. Use revert on anything that's already been pushed and shared with others; reset is fine for commits that only exist locally.
Is it safe to force-push?▼
Only if you're certain nobody else has pulled the commits you're about to overwrite. Force-pushing replaces the remote branch's history with your local version, which can silently erase a collaborator's work if they pushed in between.
How do I undo a commit I haven't pushed yet?▼
An amend if you just need to change the most recent commit's message or contents, or a reset if you want to undo it entirely and start over. Since it hasn't been pushed, rewriting it carries no risk to anyone else's copy of the history.
Why does git say I have a merge conflict?▼
Two branches changed the same lines of the same file in different ways, and git can't automatically decide which version is correct. You'll need to open the conflicting file, choose or combine the correct content, and commit the result.
Can I recover a commit after a hard reset?▼
Often yes, for a limited time. Git doesn't delete commits immediately, it keeps them reachable through its internal reflog until they're eventually cleaned up, so a recent hard reset can usually be undone if you act before too much other work happens.