Git Command Cheatsheet
Git has about 150 subcommands and several of them look dangerously similar, reset vs restore, checkout vs switch, rm vs restore --staged. This cheatsheet groups the commands you actually type by situation: daily workflow, branching, undoing mistakes, and stashing. Pick the group and copy the block.
How to use the cheatsheet
-
1
Pick a topic
Daily, branching, undo or stash: each maps to a different mental mode.
-
2
Scan the block
Every line is a complete, working command: no placeholders in angle brackets unless explicitly marked.
-
3
Copy the one you need
Paste into your terminal, adjust the branch name or commit SHA, and run.
Why commands still confuse seasoned users
Git’s porcelain grew by accretion. checkout was overloaded for “switch branch” and “restore file”; reset sits between “discard work” and “move the branch pointer”. Since Git 2.23 there are clearer verbs:
| Old | New (clearer) |
|---|---|
git checkout branch |
git switch branch |
git checkout -b new |
git switch -c new |
git checkout -- file |
git restore file |
git checkout --staged file |
git restore --staged file |
The safe undo ladder
- Restore one file:
git restore path/to/file(unstaged) orgit restore --staged path/to/file(staged but not committed). - Undo the last commit, keep changes:
git reset --soft HEAD~1. - Undo the last commit, discard changes:
git reset --hard HEAD~1(destructive; check you have no uncommitted work). - Revert a shared commit:
git revert <sha>, creates a new commit that negates the old one; safe on pushed history.
Stash etiquette
- Always stash with a message:
git stash push -m "wip: hooking up api". - List stashes with
git stash listbefore popping, anonymous stashes pile up fast. git stash popapplies and deletes;git stash applyapplies and keeps.
Recovery
Lost a commit after a hard reset? It is probably still in the reflog. Run git reflog to see every HEAD move of the last 90 days and git reset --hard <sha> back to a good state.
Frequently Asked Questions
Since Git 2.23 (August 2019) the project split the overloaded checkout verb into two. switch changes branches, restore fixes files. Both still exist for backwards compatibility but are easier to read when you revisit the shell history.
reset moves the branch pointer (and optionally the working tree). revert creates a new commit that undoes a previous one, safe on a shared branch. checkout / restore changes files in the working tree without rewriting history.
Use git revert <sha> to add a compensating commit and push that. Avoid git reset --hard + git push --force on shared branches unless the team has explicitly agreed.
The commands are static text rendered in the page. The topic you select is sent to the server only to render the matching commands, and it is carried in the page link when you move between the two steps. It is not stored or logged.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- Folha de Dicas de Comandos Git [PT]
- Bảng tra nhanh lệnh Git [VI]
- Hoja de trucos de comandos de Git [ES]
- Gitコマンドチートシート [JA]
- ورقة مرجعية لأوامر Git [AR]
- Git-kommandon fusklapp [SV]
- Feuille de triche des commandes Git [FR]
- Git-Befehlsübersicht [DE]
- คู่มือคำสั่ง Git สำหรับการใช้งานอย่างรวดเร็วและสะดวก [TH]
- Git 명령어 치트시트 [KO]
- Git-commando's spiekbriefje [NL]
- Lembar Contekan Perintah Git [ID]
- Ściąga z poleceń Git [PL]
- Шпаргалка по командам Git [RU]
- Git Komutları Kopya Kağıdı [TR]
- Git命令速查表 [ZH]
- Promemoria dei comandi Git [IT]