Manual bisect
git bisect start
git bisect bad # current HEAD is broken
git bisect good v1.2.0 # this tag was known to work
# Git checks out a midpoint; test it, then:
git bisect good # if the bug is absent
git bisect bad # if the bug is present
# when the first bad commit is found:
git bisect reset # return to the original branch
Automated bisect
If the test can run unattended, git bisect run does the whole search. The command must exit 0 for good, non-zero for bad, and 125 to skip a commit that cannot be tested (for example, a build failure unrelated to the bug).
git bisect start HEAD v1.2.0
git bisect run npm test -- --runInBand
A flaky test will send bisect down the wrong path. Use the narrowest reliable reproduction command you have.
Reading the result
Git prints the first bad commit and its diff. That commit is not necessarily the root cause — it is the first commit where the test observable fails — but it is the right place to start reading.
git bisect logrecords the decisions, useful for reproducing the search.git bisect skipexcludes a commit that cannot be built.git bisect termscustomizes labels if “good” and “bad” are confusing (for example, old/new).
Reset is not optional
Bisect leaves HEAD detached on a midpoint commit. git bisect reset returns to the branch you started from. Forgetting it is the most common bisect mistake; a commit made in that detached state can be lost.