Git Cheat Sheet: Everyday Commands and Recovery
The Git commands you use daily, and the recovery ones you need when things go wrong.
Branch, commit, sync, and undo - the Git essentials.
Branch & commit
| Command | Does |
|---|---|
| git switch -c name | New branch |
| git add -p | Stage interactively |
| git commit -m "msg" | Commit |
| git push -u origin name | Push + track |
| git pull --rebase | Update, rebasing local commits |
Inspect
| Command | Does |
|---|---|
| git status -sb | Short status |
| git log --oneline --graph | Compact history |
| git diff --staged | Staged changes |
| git blame file | Who changed each line |
Undo & recover
| Command | Does |
|---|---|
| git restore file | Discard working changes |
| git restore --staged file | Unstage |
| git commit --amend | Fix last commit |
| git reset --soft HEAD~1 | Undo commit, keep changes |
| git reflog | Find lost commits |
| git revert SHA | Safe undo (new commit) |
Related guides
Git "Host key verification failed" in CI - Fix known_hostsFix Git "Host key verification failed" in CI - the Git host is not in known_hosts, so SSH aborts before authe…
GitHub Actions Cheat Sheet: Syntax, Contexts & CommandsA GitHub Actions cheat sheet - triggers, jobs, steps, contexts, expressions, caching, matrix, and the workflo…