Essential Git commands cheat sheet

A compact, task-based reference for inspecting, staging, committing, branching, comparing, synchronizing, and recovering Git work.

Updated Command scenarios locally verified

Use this reference from inside a known repository. Start with inspection commands; they are cheap, safe, and often reveal the correct next step.

Inspect

git status --short --branch
git diff
git diff --cached
git log --oneline --graph --decorate -20
git remote -v

Stage and commit

git add path/to/file
git add -p
git commit -m "type: concise summary"
git show --stat HEAD

Review git diff --cached before committing. Avoid git add . when unrelated generated files or secrets may be present.

Synchronize

git fetch origin
git pull --ff-only
git push -u origin HEAD
git push

Compare

git diff main...feature/example
git log --oneline main..feature/example
git branch -vv

Protect work before risky operations

git branch backup/before-change
git stash push -u -m "wip before integration"
git reflog

Commands such as git reset --hard, git clean -fd, git checkout -- ., and force pushing can discard work. Prefer targeted restore, revert, a backup branch, or a named stash. Use the Git command builder for guarded common commands.

Sources and review

Last reviewed September 4, 2026. Technical claims are based on primary documentation and local command verification.