Git Command Reference

Search 50 Git recipes in plain English. Undo commits, fix mistakes, branch, rebase, stash and recover lost work, with pitfalls and copy-ready commands.

By

Advertisement

A Searchable Git Command Reference That Answers in Plain English

Most Git problems are not knowledge problems — they are recall problems. You know there is a command that un-stages a file without losing the edit, you just cannot remember whether it is git reset, git restore, or git checkout. This reference is built for that moment. Type what you are trying to do in ordinary words — “undo my last commit”, “delete a remote branch”, “save my work without committing” — and the matching recipes surface with a runnable command, an explanation of what it changes, and the pitfalls that come with it.

The library covers 50 task-focused entries across nine categories, each written as a recipe rather than a man page. Every entry carries a skill level (Beginner, Intermediate, Advanced), one or more copy-ready commands, a “when to use this” list, and where relevant a set of pitfalls. Several commands include live parameters — a slider for how many commits to go back, a field for a file path — so the command you copy already has your values substituted in.

What Is in the Reference

CategoryEntriesTypical questions it answers
Fix Mistakes10Undo a commit, amend a message, un-stage a file, discard local edits
History & Inspection10Find who changed a line, search history for a string, compare branches
Branching & Merging7Rebase vs merge, cherry-pick, squash, resolve conflicts, rename a branch
Workspace & Stash6Stash and restore work, clean untracked files, switch context mid-task
Collaboration4Push, pull, track remotes, delete a remote branch
Setup & Basics4Configure identity, clone, initialise, set the default branch
Scaling & Performance4Shallow clones, sparse checkout, partial clone, large repositories
Recovery & Safety3Recover a lost commit with the reflog, rescue a detached HEAD
Commits2Stage selectively, write commits that survive review

You can filter by category, by skill level, or both, and searching narrows within whatever filter is active. Every command block has a copy button, so nothing needs to be retyped.

How to Use It

  1. Describe the task, not the command. The search understands intent phrases. “How do I undo the last commit but keep the changes” resolves to the soft-reset recipe without you knowing the word “soft”.
  2. Ask two things at once. Queries joined with “and” are split and matched separately, so “stash my work and switch branches” returns both recipes.
  3. Filter by skill level if you want to avoid the sharp tools. Setting the filter to Beginner hides the recipes that rewrite history.
  4. Adjust the parameters. Where a recipe exposes a slider or a path field, the command text updates live — move “number of commits” to 3 and the copy button gives you HEAD~3.
  5. Read the pitfalls before running anything with --force or reset --hard. They are there because those commands destroy work in ways the message output does not warn about.

The Undo Commands, Ranked by Danger

“Undo” is the single most searched Git topic, and it maps to at least five different commands depending on what you want undone and whether it has been shared. This is the mental model the reference is organised around:

CommandWhat it changesSafe on pushed commits?
git restore <file>Discards uncommitted edits in the working treeN/A — local only, but the edits are gone
git restore --staged <file>Un-stages a file, edits untouchedYes — nothing is lost
git commit --amendReplaces the most recent commitNo — rewrites history
git reset --soft HEAD~1Removes the commit, keeps changes stagedNo — rewrites history
git reset --hard HEAD~1Removes the commit and the changesNo — and destroys uncommitted work
git revert <sha>Adds a new commit that undoes an old oneYes — history is append-only

The dividing line is whether the commit has left your machine. Anything that rewrites history is fine on a local branch and hostile on a shared one, because every collaborator’s copy now disagrees with the remote. On a branch other people have pulled, git revert is the correct tool even though it leaves a visible “Revert…” commit in the log.

Reflog: The Reason Almost Nothing Is Truly Lost

Git records every movement of HEAD in the reflog, including commits that a hard reset or a botched rebase appears to have destroyed. Those objects stay in the repository until garbage collection runs, typically 90 days later. So the recovery recipe is:

git reflog to list recent HEAD positions, find the entry from just before the mistake, then git reset --hard HEAD@{5} or git checkout -b rescue HEAD@{5} to get back to it. Creating a branch is the safer of the two, because it does not move your current branch until you have confirmed you found the right commit.

The reflog is local and per-clone. It will not recover work you never committed, and it does not exist on a fresh clone. That is the argument for committing early and often even on scratch branches — a commit is recoverable, an uncommitted working tree is not.

Rebase or Merge?

Both integrate one branch into another; they differ in what the history looks like afterwards. git merge creates a merge commit with two parents, preserving the fact that the work happened in parallel. git rebase replays your commits on top of the target branch, producing a straight line as if you had started from the latest code.

The practical rule most teams settle on: rebase your own unpushed feature branch onto main to keep it current, then merge the finished branch into main. Never rebase a branch that others have based work on. If you do need to push a rebased branch, git push --force-with-lease is strictly better than --force — it refuses the push if the remote has commits you have not seen, which is exactly the case where a force push destroys a colleague’s work. If you want to see the shape a given strategy produces before committing to it, the Git branch visualizer draws the resulting commit graph.

Frequently Asked Questions

How do I undo my last commit without losing my changes?+

git reset --soft HEAD~1 removes the commit and leaves everything staged, ready to re-commit. Use --mixed (the default) instead if you want the changes un-staged but still in the working tree. Only do this if the commit has not been pushed.

What is the difference between git reset, git revert, and git restore?+

git restore works on files in the working tree or index and does not touch commits. git reset moves your branch pointer backwards, rewriting history. git revert creates a new commit that reverses an old one, leaving history intact — the only one of the three that is safe on a shared branch.

How do I recover a commit I deleted with reset --hard?+

Run git reflog, locate the HEAD@{n} entry from before the reset, and check it out into a new branch with git checkout -b rescue HEAD@{n}. This works for roughly 90 days, until garbage collection prunes unreachable objects.

How do I delete a remote branch?+

git push origin --delete branch-name. Deleting your local copy with git branch -d branch-name does not affect the remote, and vice versa — they are separate operations.

Why does the search understand plain questions?+

Each entry carries a list of intent phrases. Your query is tokenised, stop words are removed, and it is scored against those phrases; matches above the threshold are surfaced with the phrase that matched, so you can see why a result appeared. It is lightweight keyword matching running in your browser, not a language model.

Is --force ever acceptable?+

Prefer --force-with-lease, which aborts if the remote has moved since your last fetch. Plain --force overwrites the remote unconditionally and is the standard way teams lose commits. Neither belongs anywhere near a shared main branch.

Do the commands work on Windows, macOS, and Linux?+

Yes. Git’s commands are identical across platforms. The only differences are shell quoting rules — PowerShell handles quotes and globs differently from bash — and line-ending configuration, which is what core.autocrlf controls.

Is the reference free?+

Yes, free and unlimited with no account. If you are setting up a new repository, our .gitignore generator and semantic version calculator pair well with it.

How is this Git reference organized?+

The reference is organized by practical tasks and categories including Setup and Basics, Commits, Fix Mistakes, Branching and Merging, Collaboration, History and Inspection, Workspace and Stash, Recovery and Safety, and Scaling and Performance. Each command guide includes when to use it, pro tips, and common pitfalls to avoid.

Can I search using natural language questions?+

Yes, the tool includes natural language understanding. You can type questions like "how do I undo my last commit" or "revert changes" and it will interpret your intent and show relevant Git commands. The search interprets your question and displays matching command guides ranked by relevance.

This tool is provided for informational and educational purposes only. While we strive for accuracy, we make no warranties about the completeness or reliability of results.