What is a git cheat sheet?
A git cheat sheet is a quick reference of git commands for the tasks developers do most: committing, branching, syncing with a remote and recovering from mistakes. Git has hundreds of commands and options, and even experienced developers regularly look up the less common ones.
This one lists over 40 commands grouped by topic, each with a one-line explanation. Search by command or by what you want to do, filter by topic, and copy any command with one click, then fill in its placeholders.
How to use the Git cheat sheet
1.Search
By command or task, like undo, rename or stash.
2.Filter by topic
Set up, everyday, branches, remotes, undo, releases and more.
3.Copy
Replace the <placeholders> with your values.
Example: "I committed to the wrong branch"
Searching "undo" and combining three commands:
- 1
- git reset --soft HEAD~1 (undo the commit, keep the changes)
- 2
- git switch -c <branch> (move to the right branch)
- 3
- git commit -m "message" (commit again there)
The work ends up on the right branch with nothing lost.
Undoing safely
Most git fears are about undoing. git restore discards uncommitted edits, git reset --soft HEAD~1 undoes a commit but keeps its changes, and git revert undoes a commit that's already shared by adding a new one. git reflog lists everywhere HEAD has been, so even commits lost to a hard reset can usually be recovered.
Commands that rewrite history, such as reset --hard, rebase and force pushes, are safe on your own branches but disruptive on shared ones. Prefer --force-with-lease to a plain --force.
Frequently asked questions
switch or checkout?
git switch and git restore split checkout's two jobs and are easier to get right.
merge or rebase?
Merge keeps history as it happened; rebase makes it linear. Never rebase commits others have pulled.
How do I rename the default branch?
git branch -m main, then push it and update the default on your host.
What does <url> mean?
Angle brackets mark something to replace with your own value.
Related tools
.gitignore generator
Combine .gitignore rules for your languages, frameworks, OS and editor.
Conventional commit generator
Write commit messages in the Conventional Commits format, with the git command.
Git branch name generator
Turn task titles into clean branch names like fix/login-redirect.
Semver calculator
Bump, compare and check versions against npm-style ranges like ^1.2.0.
JSON Formatter & Validator
Pretty-print, minify, sort and validate JSON with line-numbered errors.
JSON ↔ CSV Converter
Convert JSON arrays to CSV and CSV back to JSON.
More Developer tools
JSON & data
CSV tools
Network & system
Web & API
Encoding & security
- Base64 encode & decode
- URL encode & decode
- JWT decoder
- Hash generator
- HTML entity encoder
- Text to binary
- Morse code translator
- Caesar cipher & ROT13
- Random string generator
- Secret key generator
- 2FA code generator (TOTP)
- Encrypt & decrypt text
- Encrypt & decrypt files
- SSH key generator
- Base32 encoder and decoder
- Unicode escape converter
- Nano ID generator
- JWT generator
Text & code
- Regex tester
- Text diff checker
- Cron expression explainer
- Lorem ipsum generator
- Markdown previewer
- Slug generator
- Strip HTML tags
- Unicode character inspector
- URL parser
- Markdown TOC generator
- cURL converter
- Whitespace visualizer
- Markdown link extractor
- Regex escape
- Regex match extractor
- Split text by regex
- HTML, CSS and JS playground
- Mock data generator
- Keyboard event tester
- ASCII table