How to use the Git Command Generator
- Find your task in the list or search for it — “undo”, “rename”, “stash”, “squash”.
- Fill in the branch names, commit hashes or file paths the task needs.
- Read the explanation under each command; steps marked rewrites history or destructive need care on shared branches.
- 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?
| Situation | Command | Safe on pushed commits? |
|---|---|---|
| Undo last commit, keep changes | git reset --soft HEAD~1 | No — rewrites history |
| Undo a commit that others already pulled | git revert <hash> | Yes — adds a new commit |
| Throw away uncommitted changes in a file | git restore <file> | Local only |
| Fix the last commit message | git commit --amend | No — rewrites history |
| Park work-in-progress | git 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?
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?
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?
--force-with-lease, which only overwrites the remote branch if it’s still where you last saw it.