Git Commands Cheatsheet

The everyday Git commands, grouped and searchable — copy any one.

A searchable Git commands cheatsheet covering setup, staging, committing, branching, remotes, history and undoing changes. Copy any command with one click. Runs entirely in your browser, nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How do I undo my last Git commit?

Use git reset --soft HEAD~1 to undo the last commit while keeping your changes staged, or git revert <commit> to create a new commit that reverses an earlier one without rewriting history.

This is a searchable reference of the everyday Git commands developers reach for — grouped by task, each with a plain-English description and a one-click copy button. It’s built for the moments when you remember what you want to do (“undo last commit”, “rename a branch”) but not the exact flag.

How it works

The commands are organised into topic groups: setup & config, staging & committing, branching, remotes & syncing, history & inspection, and undoing & recovery. Type into the search box and the list filters live, matching both the command text and its description — so searching “undo” surfaces git reset and git revert even though neither contains the word. Click Copy next to any entry to put the exact command on your clipboard.

The most-reached-for commands

These are the commands most developers type from memory — or wish they could:

Staging and committing

git add -p              # stage changes interactively, hunk by hunk
git commit --amend      # edit the last commit message or add forgotten files
git commit -m "msg"     # one-liner commit

Branching

git switch -c feature   # create and switch to a new branch
git switch main         # switch to existing branch
git branch -d feature   # delete a branch (safe; refuses if unmerged)
git branch -m old new   # rename a branch

History

git log --oneline --graph --all   # visual branch history
git log --follow -p file          # full change history of a single file
git show HEAD                     # show the last commit in detail
git diff main..feature            # compare two branches

Undoing (the commands people forget)

git reset --soft HEAD~1   # undo last commit, keep changes staged
git reset --mixed HEAD~1  # undo last commit, unstage changes (default)
git reset --hard HEAD~1   # undo last commit AND discard changes (destructive)
git revert <hash>         # create a new commit that reverses a past commit
git restore <file>        # discard unstaged edits to one file
git restore --staged <file>  # unstage a file without losing edits
git stash                 # stash all uncommitted changes
git stash pop             # restore the most recent stash

Remotes

git fetch origin          # download changes without merging
git pull --rebase         # pull and rebase instead of merge
git push -u origin branch # push branch and set upstream tracking
git remote -v             # list remotes and their URLs

Worked example: fix a messy situation

You committed the wrong file along with your changes. Here is how to unpick it without losing work:

  1. git reset --soft HEAD~1 — uncommit everything; all changes are back in staging
  2. git restore --staged wrongfile.txt — unstage that one file
  3. git commit -m "correct commit" — re-commit only what you intended

Everything runs in your browser; nothing you type or copy is sent anywhere.