Git Bisect to Find a Bug
Use binary search through commit history with git bisect to find the exact commit that introduced a bug.
# Start bisect session
git bisect start
# Mark current commit as bad (has the bug)
git bisect bad
# Mark a known good commit (before the bug)
git bisect good v1.0.0
# or by hash:
git bisect good abc1234
# Git checks out a middle commit — test it
# If this commit has the bug:
git bisect bad
# If this commit works fine:
git bisect good
# Repeat until Git finds the culprit:
# "abc1234 is the first bad commit"
# End the bisect session
git bisect reset
# Automated bisect with a test script
git bisect start HEAD v1.0.0
git bisect run npm test
# Automated bisect with custom script
git bisect run bash -c 'node -e "require(\"./dist/app\")" 2>/dev/null'
# View bisect log
git bisect log
# Skip a commit that can't be tested
git bisect skipUse Cases
- Finding which commit introduced a regression
- Automated bug hunting across hundreds of commits
- Debugging intermittent failures in CI
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.