Quick searchable reference for everyday and recovery Git commands. Click any command or Copy button to copy it.
Category
Command
Description
Copy
Undo & Recovery
git reset --soft HEAD~1
Undo the last commit while keeping all changes staged
Undo & Recovery
git reset --mixed HEAD~1
Undo the last commit and unstage changes (keep working tree)
Undo & Recovery
git commit --amend --no-edit
Add staged changes to the previous commit without editing its message
Undo & Recovery
git checkout <commit> -- <file>
Restore a single file to its exact state from a specific commit
Undo & Recovery
git restore --staged <file>
Unstage a file without discarding your local edits
Undo & Recovery
git revert <commit>
Create a new commit that safely reverses an earlier commit (safe for shared branches)
Undo & Recovery
git reflog -n 20
View local HEAD history to recover lost commits or deleted branches
Branches & Rebase
git switch -c <branch>
Create and switch to a new branch (modern replacement for checkout -b)
Branches & Rebase
git cherry-pick <commit>
Copy a single commit from another branch onto the current branch
Branches & Rebase
git rebase -i HEAD~5
Interactively squash, reword, reorder, or drop the last 5 commits
Branches & Rebase
git fetch --prune
Remove stale remote-tracking branches that were deleted on origin
Branches & Rebase
git branch -D <branch>
Force-delete a local branch even if it has not been merged
Search & Inspect
git log -S "<text>" -p
Pickaxe search: find commits that added or removed a specific string
Search & Inspect
git log -G "<regex>" --oneline
Find commits whose diff matches a regular expression
Search & Inspect
git log --oneline --graph --decorate -n 20
Compact visual commit graph with branch and tag pointers
Search & Inspect
git show --stat <commit>
Show commit metadata and summary of changed files without full diff
Search & Inspect
git blame -L 10,30 <file>
Show who last modified lines 10 to 30 of a file and in which commit
Search & Inspect
git bisect start && git bisect bad && git bisect good <tag>
Binary-search commit history to find the exact commit that introduced a bug
Stash & Worktree
git stash push -u -m "<note>"
Stash tracked and untracked (-u) changes with a descriptive label
Stash & Worktree
git stash pop
Apply the most recent stash and remove it from the stash list
Stash & Worktree
git worktree add ../hotfix <branch>
Check out a second branch in a separate directory simultaneously
Stash & Worktree
git clean -fd
Delete untracked files and directories from the working tree (use -n first to dry-run)
Tags & Remotes
git tag -a v1.2.0 -m "Release v1.2.0"
Create an annotated release tag
Tags & Remotes
git push origin --tags
Push all local tags to origin
Tags & Remotes
git push --force-with-lease
Safely force-push after a rebase (fails if someone else pushed new commits)
Conventional Commits Quick Reference
Prefix
Meaning & SemVer Effect
feat: ...
New user-facing feature (bumps SemVer MINOR)
fix: ...
Bug fix (bumps SemVer PATCH)
feat!: ... / BREAKING CHANGE:
Incompatible API change (bumps SemVer MAJOR)
refactor: / perf:
Code restructuring or performance improvement without changing external behavior
docs: / test: / ci: / chore:
Documentation, test suite, CI pipelines, or maintenance tasks
Safe Git Recovery Rules
Prefer --force-with-lease over --force: After rebasing a feature branch, --force-with-lease refuses to overwrite the remote branch if a teammate pushed new commits you have not fetched yet.
Shared vs. Local History: Use git reset or git rebase only on unpushed or private feature branches; use git revert on main or shared release branches so you do not rewrite history for other developers.
Nothing Is Lost Immediately: Even after a hard reset or deleted branch, commits remain reachable in git reflog until garbage collection expires them (typically 30-90 days).
Please read the privacy policy (agreement of the cookies usage, other websites embedded content, etc.). If you continue to use the site, we will assume that you agree with our privacy policy.