Skip to content

Git Cheatsheet

Searchable interactive Git command reference organized by workflow - branching, merging, rebasing, and more.

Git Cheatsheet tool

Loading...

Example

Input: Search Commands: stash

Result: 7 commands found: git stash, stash pop, stash list, stash drop, stash apply, stash show and stash branch <name>, each with an example

The search matches command names, descriptions, examples, flags and categories, so a topic word finds the whole related group.

Ways to Undo Changes in Git

CommandWhat it does
git restore <file>Discards unstaged changes to a file
git reset HEAD <file>Unstages a file, keeping its changes
git reset --soft HEAD~1Removes the last commit, changes stay staged
git reset --mixed HEAD~1Removes the last commit, changes stay in files but unstaged
git reset --hard HEAD~1Removes the last commit and discards its changes
git revert <commit>Adds a new commit that undoes an old one
git clean -fdDeletes untracked files and folders

Based on the Undoing Changes entries in this cheatsheet.

  1. Browse commands by workflow section (setup, snapshotting, branching and merging, remotes, history, stashing, undoing, advanced), expanding or collapsing each section with its header.
  2. Type a keyword such as "reset", "stash", or "--amend" into the search box to filter commands by name, description, example, or flag.
  3. Click on any command row to expand its description, a practical usage example, and commonly used flags.
  4. Copy the example command you need using the copy button next to it.
  5. Open the Advanced section for less common operations like bisect, submodules, worktrees, reflog, and rebase --onto.

Git Commands Grouped by Task

This Git cheatsheet lists 56 common commands grouped by what you are trying to do, from setting up a repository to undoing a mistake. Each entry has a short explanation, a copyable example and the flags people use most. Commands sit in eight sections. They run from Setup and Config and Basic Snapshotting through Branching and Merging, Sharing and Updating, and Inspection and Comparison, to Stashing, Undoing Changes and Advanced. Each section can be collapsed. Click a row to see its example and common flags, copy the example with one click, and then swap in your own branch name or commit ID.

The search box filters as you type. It looks at command names, descriptions, examples, flags and section names. Searching stash lists all seven stash commands, and searching --amend finds git commit. That helps when you know what you want to do but not the exact command.

Read the Undoing Changes section with care. The commands look alike but behave very differently, as the table shows. git reset --hard and git clean -fd throw away uncommitted work that Git cannot bring back, so run git status first, or git clean -n to preview. If a commit seems lost after a reset, git reflog in the Advanced section usually still knows where it is. For regular expressions, see the Regex Cheatsheet.

Sources

Frequently Asked Questions

git reset moves your branch back to an earlier commit, so later commits disappear from its history. That is fine on a private branch but causes trouble on one others have pulled. git revert leaves history alone and adds a new commit that undoes an old one, which is the safe choice for shared branches such as main.
Run git reset --soft HEAD~1. The commit is removed and its changes stay staged, ready to be committed again, for example with a better message. Use --mixed instead to unstage the changes but keep them in your files. If the commit was already pushed, use git revert rather than reset.
Use git switch to change branches and git restore to discard file changes. Both were added in Git 2.23 to split up the many jobs of git checkout, which still works and appears in older guides. git switch -c name creates a branch and switches to it, like git checkout -b name.
git fetch downloads new commits from the remote but does not change your files or branches, so you can inspect them first. git pull runs a fetch and then merges the remote branch into yours, or rebases onto it with --rebase. Fetching first is the safer habit when you are unsure what changed.
Rebase replays your commits on top of another branch, giving a straight history without merge commits. It is good for tidying a private feature branch before review. Merge keeps the true history and never rewrites commits, so use it for branches others already share. Never rebase commits that others have pulled.

Related Tools

Regex Cheatsheet

Interactive regex syntax reference with descriptions, examples, and a try-it-live tester for each pattern.

DevOps Tools

Docker Run to Docker Compose Converter

Convert docker run commands to docker-compose.yml format with proper YAML structure and service configuration.

DevOps Tools

Crontab Generator

Visually build cron expressions with dropdowns, see human-readable descriptions, and preview the next 5 run times.

DevOps Tools

Text Diff and Compare Tool

Compare two blocks of text side by side and highlight the differences. Find additions, deletions, and changes instantly.

Text and Writing

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools