Git Situation → Command Finder — Free Online Tool
Find the exact Git command for your situation. Click a scenario to see the command with explanation and safety warnings.
Git Situation to Command Reference
Git is powerful but its command syntax can be hard to remember, especially for less common operations. This tool maps real-world Git situations to their exact commands, with plain-English explanations and warnings for operations that can't be undone.
Destructive vs Safe Git Operations
Some Git operations are safe and reversible (commits, branches, stashes). Others permanently alter history or can cause data loss if used carelessly:
- Safe: git stash, git branch, git checkout, git merge, git commit
- Caution needed: git reset --hard, git push --force, git rebase (rewrites history), git clean -fd
- Never do on shared branches: force-pushing to main/master, rebasing public commits
Git Best Practices
- Always create a branch before making changes — never work directly on main
- Commit often with clear, descriptive messages
- Use
git statusandgit diffbefore committing - Prefer
git revertovergit reset --hardon shared branches - Use
git stashto temporarily save work-in-progress
Git Workflows for Teams: Choosing the Right Strategy
Choosing the right Git workflow is one of the most impactful decisions for team productivity. The wrong workflow creates merge conflicts, blocks deployments, and slows down code review. Here are the most popular strategies and when to use each.
Popular Git Branching Strategies
- GitHub Flow: Simple and effective. Create feature branches from main, open PRs, merge after review. Best for teams with continuous deployment and small, frequent releases. Used by GitHub, Shopify, and many startups.
- GitFlow: Uses develop, feature, release, and hotfix branches. More structured but heavier. Best for teams with scheduled releases (mobile apps, enterprise software). Can create merge bottlenecks if not managed well.
- Trunk-Based Development: Everyone commits to main (trunk) frequently, using short-lived feature branches (1-2 days max). Requires feature flags for incomplete work. Used by Google, Facebook, and Netflix. Best for experienced teams with strong CI/CD.
Git Commands Every Developer Should Master
- git rebase -i: Interactive rebase lets you squash, reorder, edit, and drop commits before pushing. Essential for clean, reviewable commit history. Use git rebase -i HEAD~5 to restructure your last 5 commits.
- git bisect: Binary search through commits to find which commit introduced a bug. Automated with git bisect run <test-command>. Can find a bug in 1000 commits with just 10 steps.
- git stash: Temporarily shelve changes to switch branches. Use git stash push -m "description" with a message so you remember what each stash contains.
- git reflog: Your safety net — shows every HEAD movement, even after resets and rebases. If you lose commits, git reflog can help recover them within 90 days.
Frequently Asked Questions about Git
How do I undo my last git commit without losing my changes?
Use git reset --soft HEAD~1 to undo the last commit but keep all changes staged. Use git reset HEAD~1 (mixed mode, the default) to undo the commit and unstage changes while keeping them in your working directory. Only use git reset --hard HEAD~1 if you want to permanently discard all changes — this cannot be undone once done.
How do I delete a local and remote branch?
Delete a local branch with git branch -d branch-name (safe, requires the branch to be merged) or git branch -D branch-name (force delete regardless). Delete a remote branch with git push origin --delete branch-name. To clean up stale remote-tracking references locally, run git fetch --prune or git remote prune origin.
What is the difference between git merge and git rebase?
git merge creates a new merge commit joining two branches while preserving full history. git rebase replays your commits on top of another branch, producing a cleaner linear history. Use merge for public and shared branches — it is safe and non-destructive. Use rebase only on local feature branches before merging. Never rebase commits already pushed to a shared remote branch — it rewrites history and forces other contributors to reconcile diverged histories.
How do I see what changed in the last commit?
Use git show to see the diff of the most recent commit including commit message, author, date, and full patch. For a summary without the full diff, use git show --stat. To compare two specific commits, use git diff commit1 commit2. To see the history of a specific file, use git log --follow -p -- filename.
Related Developer Tools
- SemVer Calculator — calculate semantic version bumps and validate npm version ranges
- Docker Compose Generator — generate docker-compose.yml with networks, volumes, and env vars
- .ENV File Inspector — detect exposed secrets and generate safe .env.example files
- Regex Tester & Explainer — test regex patterns with live highlighting and explanations
- View all free developer tools