Git Command Builder
Build the right git command for common workflows.
Undo the last commit, keep the changes | git reset --soft HEAD~1 Moves HEAD back one commit; your files and staging area are untouched. |
Undo the last commit and discard changes destructive | git reset --hard HEAD~1 Permanently drops the commit and its changes. |
Fix the last commit message | git commit --amend -m "new message" Rewrites history — avoid on branches others have pulled. |
Unstage a file | git restore --staged path/to/file Keeps the working-tree changes, removes them from the index. |
Discard local changes to a file destructive | git restore path/to/file Overwrites the file from HEAD. |
Create and switch to a branch | git switch -c feature/my-change Modern replacement for git checkout -b. |
Rename the current branch | git branch -m new-name Push with --set-upstream afterwards to update the remote. |
Delete a remote branch destructive | git push origin --delete feature/old Removes the branch on the remote only. |
Stash work in progress | git stash push -m 'wip' Restore with git stash pop. |
Apply one commit onto this branch | git cherry-pick <sha> Use -x to record the original commit reference. |
Clean up the last N commits | git rebase -i HEAD~5 Squash, reorder or reword before opening a PR. |
Sync a fork with upstream | git fetch upstream && git rebase upstream/main Add the remote once: git remote add upstream <url>. |
Find the commit that introduced a bug | git bisect start && git bisect bad && git bisect good <sha> Binary search across history; finish with git bisect reset. |
See who changed a line | git blame -L 10,20 path/to/file Add -w to ignore whitespace-only changes. |
Search all history for a string | git log -S "functionName" --oneline Pickaxe search finds commits that added or removed the text. |
Remove untracked files destructive | git clean -fd Dry-run first with git clean -nd. |
Tag and push a release | git tag -a v1.2.0 -m "Release 1.2.0" && git push origin v1.2.0 Annotated tags carry a message and author. |
Remove stale remote-tracking branches | git fetch --prune Cleans up branches deleted on the remote. |