Git has hundreds of commands. You will use about a dozen of them every day. This is the list I keep open in a second tab — the muscle-memory commands grouped by what you're actually trying to do, with the flags that matter and the ones that don't cluttering nothing.
01/Daily drivers
These are the five commands I run more than anything else. Status to know where I am, diff to see what I changed, add to stage, commit to save, push to share. If you only learn five, learn these.
// Where am I and what changed git status git diff git diff --staged // Stage changes hunk-by-hunk so nothing sneaks in git add -p // Commit with a one-line subject git commit -m "Fix checkout redirect on empty cart" // Push to the upstream branch (set with -u the first time) git push
02/Branching & switching
git switch is the modern, less-overloaded command for moving between branches. git checkout -b still works and is what most muscle memory remembers, so both are below. The -D flag force-deletes a branch even if it's unmerged — only use it when you know what you're throwing away.
// Create a new branch and switch to it git checkout -b add-stripe-webhook git switch -c add-stripe-webhook // Switch to an existing branch git switch main // List local branches; -a includes remotes git branch git branch -a // Delete merged branch (-d safe, -D force) git branch -d add-stripe-webhook git branch -D abandoned-experiment
03/Undo, safely
Most "I broke Git" situations are recoverable if you reach for the right undo. git restore is the modern way to throw away unstaged changes. git reset --soft HEAD~1 rewinds the last commit but keeps the diff staged, so you can rewrite the message or split the commit. git revert is the only safe undo for a commit that's already on a shared branch — it adds an inverse commit instead of rewriting history.
// Throw away unstaged edits in a single file git restore src/checkout.ts // Unstage a file but keep the edits in your working tree git restore --staged src/checkout.ts // Rewind last commit, keep changes staged git reset --soft HEAD~1 // Revert a pushed commit by adding the inverse git revert abc1234
What not to do: never git push --force to a shared branch like main. If you need to update a force-pushed feature branch and someone else pulled it, use --force-with-lease instead — it refuses to overwrite work you haven't seen.
04/Inspect & blame
Before you change anything, look. git log shows you the history, git show shows you a single commit's diff, and git blame tells you who last touched a line and in which commit — invaluable when you're trying to understand why a piece of code exists.
// Compact log — one line per commit git log --oneline // Log with diffs (paged — hit q to exit) git log -p // Inspect a single commit by SHA git show abc1234 // Who last touched each line of a file git blame src/checkout.ts
Tip: git log --oneline --graph --decorate draws a tiny ASCII graph of branches and merges. Set it as a Git alias (git config --global alias.lg) so you can type git lg instead of remembering four flags.