How to use git bisect to find bugs

· Category: Git

Short answer

git bisect performs a binary search between a good and bad commit to find the exact commit that introduced a bug.

Steps

  1. Start bisect:
git bisect start
  1. Mark the current commit as bad:
git bisect bad
  1. Mark a known good commit:
git bisect good v1.0.0
  1. Git checks out a middle commit; test and mark good or bad.
  2. Repeat until the culprit is found, then reset:
git bisect reset

Tips

  • Automate testing with git bisect run <script>.
  • Choose the widest possible range for faster narrowing.
  • Document the bad commit in your issue tracker.

Common issues

  • Flaky tests can mislead bisect; ensure reliable reproduction.
  • Skipping commits with git bisect skip helps when a commit is unbuildable.