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.

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.

What Is Git Command Reference

Git is the most widely used distributed version control system, tracking changes to source code across software development projects. With over 150 commands and thousands of flags, Git's command-line interface is powerful but complex. Even experienced developers regularly look up less common commands, flag combinations, and workflows.

This tool provides a searchable reference for Git commands organized by workflow — from basic operations to advanced rebasing, bisecting, and repository maintenance.

Essential Git Commands by Workflow

Daily Development

CommandPurposeExample
git statusShow working tree statusgit status -sb
git addStage changesgit add -p (interactive staging)
git commitRecord changesgit commit -m "Fix login timeout"
git pullFetch and merge remote changesgit pull --rebase origin main
git pushUpload local commitsgit push origin feature-branch
git diffShow unstaged changesgit diff --cached (staged changes)
git logView commit historygit log --oneline --graph
git stashTemporarily shelve changesgit stash push -m "WIP login fix"

Branching and Merging

CommandPurposeExample
git branchList, create, delete branchesgit branch -d feature-branch
git checkoutSwitch branches or restore filesgit checkout -b new-feature
git switchSwitch branches (modern)git switch -c new-feature
git mergeCombine branch historiesgit merge --no-ff feature-branch
git rebaseReapply commits on new basegit rebase main
git cherry-pickApply specific commitsgit cherry-pick abc1234

Common Use Cases

  • Command lookup: Quickly find the correct syntax and flags for Git operations you perform infrequently
  • Workflow standardization: Generate consistent Git commands for team workflows (branching strategies, commit conventions, merge methods)
  • Troubleshooting: Find commands for recovering from common Git mistakes (wrong branch, bad merge, lost commits)
  • Learning Git: Explore Git commands with explanations of what each flag does and when to use different options
  • Script generation: Generate Git commands for automation scripts, CI/CD pipelines, and deployment workflows

Best Practices

  1. Use conventional commits — Structure commit messages as type(scope): description (e.g., "fix(auth): resolve session timeout") for automated changelogs and SemVer bumping.
  2. Prefer rebase for feature branches — git pull --rebase keeps history linear. Merge commits from git pull create unnecessary noise in the log.
  3. Never force-push to shared branches — git push --force rewrites remote history and can destroy teammates' work. Use --force-with-lease if you must rewrite a shared branch.
  4. Use interactive staging — git add -p lets you stage individual hunks within files, creating focused commits that are easier to review and revert.
  5. Write meaningful commit messages — The first line should summarize the change in 50 characters. The body should explain why, not what (the diff shows what).

Frequently Asked Questions

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.

What skill levels are the commands categorized by?+

Commands are tagged as Beginner, Intermediate, or Advanced. Beginners can focus on essential commands like git add, commit, and push. Intermediate users can explore branching, merging, and stashing. Advanced users can find commands for rebasing, cherry-picking, and repository maintenance.

How do I copy commands to use in my terminal?+

Each command example has a Copy button that copies the exact command to your clipboard. Many commands also include adjustable parameters with sliders or text inputs, so you can customize values like commit counts or file paths before copying. The command updates in real-time as you adjust parameters.

What are the Common Pitfalls sections?+

Common Pitfalls highlight dangerous operations or frequently made mistakes for each command. These warnings help you avoid accidentally losing work, corrupting your repository, or creating problems for your team. They are especially important for destructive commands like force push or hard reset.

Does this reference include alternative commands?+

Yes, many command guides include an Alternatives section showing different ways to accomplish the same task. This helps you choose the right approach based on your specific situation. For example, undoing changes might show options for both local and already-pushed commits.

Can I navigate to related Git commands?+

Yes, each command guide includes a Related section with links to other relevant commands. Clicking a related command jumps directly to that guide. This helps you discover connected workflows, like going from staging to committing to pushing, or from creating a branch to merging it.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.