Sub topic 7
Letting git bisect run do the search
This chapter assumes you can start and end a manual bisect session. It also assumes you have a script that exits with the codes Git expects: 0 for good, 1 to 127 (except 125) for bad, 125 for skip. Here you hand the loop to Git.
What git bisect run does
In a manual session you check out each midpoint, test it, and type git bisect good or git bisect bad. git bisect run does this loop for you. At each step Git:
- Checks out the midpoint commit.
- Runs your command.
- Reads the exit status and marks the commit good, bad, or skipped.
- Narrows the range and repeats until one commit is left.
The full session
Start the session with the bad commit first and the good commit second. Then hand over the script:
git bisect start HEAD v1.4.0
git bisect run ./check.sh
git bisect resetgit bisect start HEAD v1.4.0 marks HEAD as bad and the v1.4.0 tag as good. git bisect run ./check.sh runs the search to the end. git bisect reset returns you to the branch you started on.
Passing a command
Everything after run is the command Git executes. It can be a script, a program with arguments, or a shell one-liner:
git bisect run sh -c 'make || exit 125; ./run_regression_test.sh'The sh -c form avoids a separate file. The make || exit 125 part reports a build failure as "cannot test" instead of "bad". A commit that fails to build says nothing about your regression.
The last command in the string decides the exit status. Here that is ./run_regression_test.sh.
Reading the output
Git prints a progress line before each test. It prints the culprit at the end. The output below is shortened, and the exact wording varies by Git version.
running './check.sh'
Bisecting: 3 revisions left to test after this (roughly 2 steps)
...
4f1c9e2a7d0b5c3e8a6f1b2d9c4e7a0b3d5f8c61 is the first bad commit
commit 4f1c9e2a7d0b5c3e8a6f1b2d9c4e7a0b3d5f8c61
Author: A. Developer <[email protected]>
Date: Tue Mar 3 11:20:45 2026 +0000
Cache parsed config between requests
bisect found first bad commitThe hash on the "is the first bad commit" line is the answer. Inspect it with git show before you act on it. The next chapters cover that.
Why a run stops early
Git stops the run, without finishing the search, in these cases:
- The script exits with 128 or higher. Git treats this as "something is broken, abort". A script killed by a signal, or a missing interpreter (exit 127 is still "bad", but 128+ is not), can end the run.
- The starting commits are inconsistent. If your "good" commit actually fails, the result is meaningless. Git can refuse to continue when the good commit is not an ancestor of the bad one.
- The script cannot be found. If checkout removes or replaces
check.sh, every later step fails. Keep the script outside the working tree, or untracked.
Checking the work afterwards
The search assumes that history goes from good to bad exactly once. If a commit in the middle was misjudged, the answer is wrong, but Git cannot tell. A cheap check is to test the reported commit and its parent:
git checkout 4f1c9e2^ && ./check.sh; echo "parent: $?"
git checkout 4f1c9e2 && ./check.sh; echo "culprit: $?"The parent should print 0 and the culprit should print non-zero. If that holds, the result is consistent with what you tested.
Exercise
Your script is ./check.sh. You run git bisect start HEAD v1.4.0 and then git bisect run ./check.sh. Git reports the very first commit after v1.4.0 as the first bad commit, but you know the bug is much newer. What is the most likely cause, and how do you confirm it?
Show answer
The script is probably returning a non-zero code for a reason unrelated to the regression, such as a failed build or a wrong path, so every commit looks bad. Confirm by checking out v1.4.0, running ./check.sh; echo $?, and seeing a non-zero result. Fix it by making the script exit 125 when it cannot build or test, and 0 only when the regression test passes.