How to use the Git Cheat Sheet
- Type your own values (branch, remote, file, commit) in the boxes at the top — every example on the page updates instantly.
- Search or jump to a section to find the command you need.
- Click Copy to copy a ready-to-run line, or Copy section for a commented block.
- Commands marked destructive delete or overwrite data — read the note before running them.
The Git workflow in one minute
Most work follows the same loop: create a branch with git switch -c, make changes, review them with git diff, stage with git add -p, commit, and push with git push -u. Before opening a pull request, update your branch with git pull --rebase origin main so it applies cleanly.
Commands that rewrite history
commit --amend, rebase, reset and push --force change existing commits. That is fine on a branch only you use, but on shared branches it forces everyone else to repair their copies. On shared branches undo with git revert, and if you must force-push, use --force-with-lease.
Nothing is lost for 30 days
Even after a bad reset --hard or rebase, committed work is still in the repository. git reflog lists where HEAD has been, so you can return to any recent state. Uncommitted changes are the exception — commit or stash often.
Generate commands for specific situations with the Git command generator and start new repositories with the .gitignore generator.
Tools that pair well with the Git Cheat Sheet
- Docker Cheat Sheet — The Docker and Docker Compose commands you reach for every week, explained in one line.
- Linux Commands Cheat Sheet — The Linux and bash commands developers use on servers and laptops — files, search, permissions, processes, logs, networking and SSH.
- AI Prompts for Developers — Battle-tested prompts for the coding tasks you do every day — debugging, reviews, tests, refactoring, SQL, commit messages and documentation.
Frequently asked questions
What is the difference between git fetch and git pull?
git fetch downloads new commits from the remote but does not touch your branch. git pull fetches and then merges (or rebases) them into your current branch.How do I undo the last commit?
git reset --soft HEAD~1 to undo the commit and keep the changes staged. If the commit is already pushed to a shared branch, use git revert <commit> instead so nobody’s history is rewritten.Should I use merge or rebase?
How do I get back a commit I lost after a reset?
git reflog, find the line from before the reset, and run git reset --hard HEAD@{n} or create a branch from that commit hash.