Git Command Generator — Undo, Branch, Stash, Rebase & More

Pick a task like “undo the last commit but keep my changes” or “rename a branch on GitHub”, fill in your branch names and get the exact Git commands — each line explained, risky steps flagged.

Runs in your browser

    Your data never leaves your computer. All processing happens 100% locally in your browser.

    How to use the Git Command Generator

    1. Find your task in the list or search for it — “undo”, “rename”, “stash”, “squash”.
    2. Fill in the branch names, commit hashes or file paths the task needs.
    3. Read the explanation under each command; steps marked rewrites history or destructive need care on shared branches.
    4. Copy a single command or all of them and run them in your terminal from the repository folder.

    Undoing things in Git — which command when?

    SituationCommandSafe on pushed commits?
    Undo last commit, keep changesgit reset --soft HEAD~1No — rewrites history
    Undo a commit that others already pulledgit revert <hash>Yes — adds a new commit
    Throw away uncommitted changes in a filegit restore <file>Local only
    Fix the last commit messagegit commit --amendNo — rewrites history
    Park work-in-progressgit stash push -m "…"Local only

    Rewriting history safely

    Commands like reset, commit --amend and interactive rebase create new commits with new hashes. That’s fine on your own branch, but on a shared branch everyone else’s history no longer matches. If you must push rewritten history, use git push --force-with-lease: unlike --force, it refuses to overwrite commits on the remote that you haven’t seen.

    Modern commands: switch and restore

    Since Git 2.23, git switch (change branches) and git restore (restore files) split the overloaded git checkout into two clearer commands. This generator uses them where they make things clearer. Before you push, keep your repository clean with a proper .gitignore, write release notes with the Changelog Generator and choose version numbers with the Semantic Version Calculator.

    Tools that pair well with the Git Command Generator

    • GitHub Actions Workflow Generator — Choose your stack, triggers and steps and get a commented .github/workflows/ci.yml — install, cache, lint, test, build, a version matrix and optional deploy to GitHub Pages, Vercel or a container registry.
    • README Generator — Fill in a few fields and get a clean, GitHub-ready README.md — badges, installation, usage example, configuration table, environment variables, roadmap and license — with a live preview and a completeness check.
    • Diff Checker — Paste an original and a changed version to see added, removed and modified lines side by side — with the exact words that changed highlighted inside each line.
    • package.json Generator — Fill in a form and get a valid package.json — npm name validation, script presets for Vite, Next.js, Node and TypeScript libraries, exports, engines, license and repository — with warnings for common mistakes.

    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. Use --mixed (the default) to keep them unstaged instead. Don’t do this on commits you’ve already pushed to a shared branch — use git revert there.
    What is the difference between git reset and git revert?
    reset moves the branch pointer back and removes commits from history. revert keeps history and adds a new commit that undoes the changes, which is safe for commits others already have.
    How do I rename a branch locally and on GitHub?
    Rename locally with git branch -m old new, push the new name with git push -u origin new and delete the old one with git push origin --delete old. Update the default branch in the GitHub settings if needed.
    Is git push --force dangerous?
    Yes, it can delete commits other people pushed. Prefer --force-with-lease, which only overwrites the remote branch if it’s still where you last saw it.

    Related tools