Git Bisect Cheat Sheet

Git bisect — binary search through commits to find exactly which change introduced a bug. Automation with scripts and best practices.

Last Updated: May 1, 2025

Manual Bisect

git bisect start
Begin a bisect session
git bisect bad HEAD
Mark current commit as bad (has the bug)
git bisect good v1.0
Mark a known-good commit as bug-free
git bisect good
Mark currently checked-out commit as good
git bisect bad
Mark currently checked-out commit as bad
git bisect reset
End bisect and return to original branch
git bisect log
Show all steps taken so far
git bisect visualize
Open gitk to see remaining suspect commits

Automated Bisect

git bisect run ./test.sh
Auto-bisect: script exits 0=good, 1-127=bad
git bisect run npm test
Run test suite automatically on each step
git bisect run python -m pytest test_bug.py
Target a specific test
git bisect run sh -c 'make && ./test'
Build then test at each step
git bisect run ~/bisect-script.sh
Use a saved script for complex checks
git bisect skip
Skip a commit that can't be tested (broken build)
git bisect replay logfile
Replay a previous bisect from its log

Bisect Strategy

ItemDescription
Mark Range FirstAlways start by marking one good and one bad commit
Skip UntestableUse skip for commits that don't compile or have unrelated failures
Test One BehaviorBisect for one bug at a time — don't mix issues
Write a ScriptFor anything beyond 10 commits, automation saves enormous time
Old Bug, New BranchBisect on a fresh branch to avoid interfering with work
Save the Loggit bisect log > bisect.log — you may need it for documentation
Blame vs Bisectgit blame tells you who, bisect tells you when
Terminology Switchgit bisect terms new/old for non-bug scenarios
Pro Tip: Automate bisect with `git bisect run ./test.sh` — it will find the offending commit in log2(N) steps while you get coffee.