Git Bisect: Finding Bugs Fast
Thu Aug 14 2025
Binary search over history beats scanning diffs manually.
1. Identify Good & Bad Commits
Find a recent bad commit (failing) and an older good commit (working).
2. Start Bisect
git bisect start git bisect bad <bad-hash> git bisect good <good-hash>
3. Test Each Step
Git checks out midpoint. Run your failing test or manual repro script. Mark result:
git bisect good # if pass git bisect bad # if fail
4. Automate (Optional)
If you have a deterministic script returning 0/1:
git bisect run ./scripts/repro.sh
5. Finish
When bisect ends, it prints the first bad commit.
6. Patch & Validate
Create a fix branch from that commit or latest main, patch, and confirm test passes.
7. Add Regression Test
Prevent recurrence by encoding the failure in a test.
8. Reset State
git bisect reset
9. Tips
- Skip flaky commits:
git bisect skip
- Tag releases to speed future hunts.
10. Summary Template
Issue: Range: Root cause commit: Fix commit: Regression test: Lessons:
Bisect turns mysteries into certainty.