Git Command Generator
Pick what you want to do, like undo a commit or rename a branch, and get the right git commands explained.
How to use the Git Command Generator
- 1Pick what you want to do from the list, or search for it, e.g. undo, rename or stash.
- 2Fill in branch names, commit counts or messages, and say whether the branch was already pushed.
- 3Copy the commands. Every flag is explained, and commands that can lose work are marked in red.
About Git Command Generator
The Git Command Generator answers the question how do I do this in Git with the exact commands. Pick one of 28 tasks grouped into undo and fix, commits and history, branches, remotes, and stash and clean, or search for keywords such as undo, rename, squash or stash. Typical tasks include undoing the last commit, renaming a branch locally and on the remote, squashing commits, cherry-picking, recovering lost work and syncing a fork.
Fill in branch names, commit counts, messages or remote URLs, and say whether the branch was already pushed. The commands adjust to your answers, for example using git revert instead of rewriting history on a shared branch, or adding a force push with --force-with-lease when one is needed. Every flag is explained, and steps that can lose work are marked in red.
It works as an interactive git cheat sheet for developers who use Git every day but don't remember the right options for rarer jobs, and for beginners who want to understand what a command does before they run it.
Frequently asked questions
How do I undo the last commit but keep my changes?
Run git reset --soft HEAD~1. The commit disappears and its changes stay staged. If the commit was already pushed to a shared branch, use git revert instead, which adds a new commit that undoes it.
What is the difference between git reset and git revert?
reset moves the branch back and rewrites history, which is fine for local commits. revert adds a new commit that undoes an old one, so history stays intact and it is safe on branches others have pulled.
Why --force-with-lease instead of --force?
Both overwrite the remote branch, but --force-with-lease refuses when someone else pushed in the meantime, so you don't silently delete their commits.
How do I get back a commit I lost with reset --hard?
Run git reflog to see every position HEAD has been at, find the commit and create a branch on it with git branch recovered <hash>. This works for about 30 days, until Git's garbage collection removes unreachable commits.
More in Developer Tools
Generate strong passwords and memorable passphrases.
Create QR codes for links, Wi-Fi and contacts with custom colors.
Get lorem ipsum and realistic test data as JSON, CSV or SQL.