Git cheatsheet
A cheat sheet of common Git commands for when you have forgotten the exact flags.
Git is a decentralized version management software. With this cheatsheet, you will have quick access to the most common git commands.
Steps and notes
What is Git cheatsheet?
Git's model is simple; its flag surface is not. Everyone re-learns the same half-dozen situations: undoing a commit, squashing before a pull request, un-staging a file, pointing a branch at the right remote. This cheat sheet organises those recurring situations by category and gives one copy-paste command per scenario, with placeholders for the parts that vary (branch names, file names, commit ranges). It is deliberately a reference, not a tutorial: each entry assumes you know what the operation means and just need the exact syntax, so you can get back to work in seconds. For anything beyond the everyday cases — interactive rebase surgery, reflog archaeology, submodule workflows — the entries link the concept name you should search for next.
- Find the scenario by category
- Copy the command
- Replace the placeholders with your own branch or file names
- Square-bracketed tokens such as [name], [url] and [commit message] are placeholders — replace them before running; they are not literal arguments
- Several entries rewrite history or move HEAD (amend, reset). Doing that to commits you have already pushed rewrites shared history — keep them for local work, or push with --force-with-lease when you must
Frequently asked questions
- Do I need to change anything before pasting a command?
- Usually yes — the placeholders. Commands are shown with tokens like your-branch or file-name standing in for the values that differ per situation. Replace them with your own branch, file or commit range; the surrounding flags are already correct.
- Is this a Git tutorial?
- No, and that is on purpose. Each entry is one command for one recognised situation, assuming you already know what the operation does. If you are unsure what a command will change, run it with --dry-run where available or check the linked concept in the official documentation first.
- I ran a command from the list and want to undo it — is that covered?
- The undo scenarios (un-staging, amending, resetting a commit, restoring a file) are their own category precisely because they get forgotten. For anything else, git reflog records where HEAD has been, which is the general escape hatch when a listed command did something unexpected.
Category: Development
DevOps & configs workflow
Chmod Calculator — Unix File Permissions (755, 644, 777) → Crontab Generator — Cron Expressions with Plain-English Preview → Docker Run to Compose Converter — Generate a compose Service from a Command → Linux commands cheat sheet → Git cheatsheet