Git Command Builder & Cheatsheet
Search for what you want to do — undo a commit, rename a branch, squash history — and get the exact git command with an explanation. 50+ common tasks organised by category.
What is Git?
Git is a distributed version control system that tracks changes to files over time, allowing multiple people to collaborate on a project, revert to previous states, and manage parallel lines of development through branches. While powerful, git's command-line interface has hundreds of commands and flags — many developers know the basics (add, commit, push, pull) but reach for Stack Overflow whenever they need to undo something, rewrite history, or manage branches. This tool collects the most commonly needed git commands in one searchable place.
How to Use This Tool
- Search by what you want to do — type "undo", "rename branch", "discard changes", "squash" and find the matching command.
- Filter by category — branches, commits, undo/recovery, remotes, stashing, and history.
- Copy with one click — every command has a copy button so you can paste it directly into your terminal.
- Read the explanation — each command includes what it does and any warnings about destructive operations.
Understanding Git's Three Areas
Git tracks your project through three conceptual areas: the working directory (your actual files as you edit them), the staging area or "index" (changes you've marked with git add to be included in the next commit), and the repository (the committed history stored in the .git folder). Most confusion with git commands comes from not knowing which area a command operates on — for example, git checkout -- file discards working directory changes, while git reset HEAD file unstages a file without touching its content.
Frequently Asked Questions
git reset --soft HEAD~1. This moves the branch pointer back one commit but keeps all your changes staged, ready to be re-committed (perhaps with a better message). If you want the changes unstaged too, use git reset HEAD~1 (mixed reset, the default).git merge combines two branches by creating a new "merge commit" that has two parents — it preserves the exact history of both branches but can create a cluttered, non-linear history. git rebase replays your commits on top of another branch, creating a clean, linear history — but it rewrites commit hashes, which is dangerous on commits that have already been pushed and shared with others. The general rule: never rebase commits that other people have already pulled.git reflog to see a log of where HEAD has pointed recently, including the last commit of the deleted branch. Find the commit hash from before the deletion, then run git checkout -b branch-name <commit-hash> to recreate the branch at that point. The reflog typically retains entries for about 30-90 days by default.git checkout main) to discard the detached state, or create a new branch from your current position (git checkout -b new-branch-name) to keep your work.git pull (which merges or rebases the remote changes into yours) before pushing again. Avoid git push --force on shared branches, as it can overwrite others' work — use --force-with-lease if you must force-push, as it fails safely if someone else has pushed in the meantime.git rebase -i HEAD~N (where N is the number of commits to combine), then in the editor that opens, change "pick" to "squash" (or "s") for all commits except the first one. Save and close — git will combine them and prompt you to write a new combined commit message. Alternatively, for the simplest case, git reset --soft HEAD~N followed by a fresh git commit achieves the same result.