How to Find a Bad Commit With git bisect
git bisect performs a binary search through your commit history to find exactly which commit introduced a bug.
Published September 28, 2026
git bisect performs a binary search through history to find the commit that introduced a bug. You mark commits good or bad and Git narrows it down quickly.
How it works
Start by telling Git a bad commit (usually HEAD) and a known good one. Git checks out the midpoint; you test and mark it, and repeat.
With 1,000 commits it takes about 10 steps. You can automate it with a test script.
Try it
git bisect start
git bisect bad
git bisect good v1.0
Bisecting: 5 revisions left to test
git bisect good
a1b2c3d is the first bad commit
Practical examples
Manual bisect
git bisect start
git bisect bad
git bisect good v1.0.0Finish
git bisect resetAutomate with a script
git bisect run npm testSkip an untestable commit
git bisect skipCommon mistakes
- Marking the wrong result and misleading the search.
- Forgetting git bisect reset.
- Testing with uncommitted local changes.
Key takeaways
- Binary search finds the culprit commit.
- Mark good/bad until done.
- bisect run automates it.
FAQ
How many steps?
About log2 of the number of commits.
Can it find a fix?
Yes, with custom terms like git bisect start --term-new=fixed --term-old=broken.