Skip to content

Git Command Generator

Find the git command for what you are trying to do, with what it does and what it can destroy.

Runs in your browserNo account neededFree
Loading tool…

Processing: This tool runs entirely in your browser. Your input and any file you open stay on your device — nothing is uploaded to a server.

How to use the git command generator

  1. Search or browse for the task you are trying to do.
  2. Fill in the branch, file or commit if the command needs one.
  3. Read what it does — and what it destroys — before copying it.

About this tool

Commands are organised by what you are trying to do rather than alphabetically, because the difficulty with git is rarely the syntax. "Undo the last commit" is three different commands depending on what you mean by undo — keep the changes, discard them, or reverse a commit others have already pulled — and choosing wrong is how work disappears.

So each entry says what it actually does, and the destructive ones say what they destroy and whether anything can bring it back. That distinction matters more than it looks: a `git reset --hard` loses uncommitted work permanently, while the commit it moved away from sits in the reflog for weeks. Knowing which half of your work is recoverable is the difference between a bad afternoon and a lost one.

Where a safer alternative exists it is offered beside the command with the condition attached. Reverting rather than resetting on a shared branch, merging rather than rebasing when others have the commits, `--force-with-lease` rather than `--force` when a push has to be forced at all.

The reflog entry is the one worth knowing before you need it. It lists every position HEAD has held, including commits no branch points at any more, and it is what makes most git accidents recoverable by someone who knows it exists.

Common uses

  • Undoing a commit correctly depending on whether it was pushed.
  • Recovering a file or a branch after a mistake.
  • Finding which commit introduced a particular line.

Frequently asked questions

How do I undo the last commit?
Depends what you mean. Keep the changes with git reset --soft HEAD~1, discard them with --hard, or reverse an already-pushed commit with git revert, which does not rewrite history.
What is the difference between reset and revert?
Reset moves the branch pointer and rewrites history. Revert adds a new commit that undoes an old one, leaving history intact — which is what a shared branch needs.
Can I recover from a hard reset?
The commits, usually — git reflog lists positions HEAD has held and you can reset back. Work that was never committed is gone, which is the real risk.

Related tools