Sub topic 2
A manual bisect session: start, good, bad, reset
This chapter walks through one complete git bisect session by hand. It assumes you are comfortable with commits, branches, tags and git checkout, and that you can build and run your project's tests from a shell. Doing the search manually first shows what git bisect run automates later.
The situation
Suppose the tag v1.4.0 worked and main is now broken. Between them lie 64 commits. You want the first commit where the bug appears. Git calls the working end the good commit and the broken end the bad commit.
Each time you tell Git whether a commit is good or bad, it checks out the commit halfway through the remaining range. Each answer halves the range, so 64 commits need at most 6 tests, because log2(64) = 6.
Step 1: start the session
Begin from a clean working tree. Git will move you between commits, and uncommitted changes can get in the way.
git bisect start
git bisect bad HEAD
git bisect good v1.4.0After you give both endpoints, Git prints how many revisions remain and checks out a middle commit. The output looks like this:
Bisecting: 31 revisions left to test after this (roughly 5 steps)
[3f9a1c2...] Refactor config loaderYou can also pass both endpoints to start in one line: git bisect start HEAD v1.4.0. The first argument is bad and the second is good.
Step 2: test and report
Build the project and run the check that shows the bug. Then report the result:
make && ./run_regression_test.sh
git bisect good # the bug is absent here
# or
git bisect bad # the bug is present hereGit responds with a new midpoint and a new estimate of the steps left. Repeat until Git ends with a message like this:
3f9a1c2d0e... is the first bad commit
commit 3f9a1c2d0e...
Author: A. Developer <[email protected]>
Date: Tue Oct 6 14:02:11 2026 +0000
Cache parsed config between requestsThat commit is the first one where the test fails. Every commit before it in the searched range passed.
Step 3: reset
The session leaves your repository on a detached HEAD at the culprit commit. End the session to return to the branch you started from:
git bisect resetWithout this step, later commits would land on a detached HEAD and be easy to lose. Run git bisect reset even if you abandon the search halfway.
Mistakes to watch for
- Swapped endpoints. If you mark the new commit good and the old one bad, Git can report a wrong result or refuse with an error. Check which end is broken before you start.
- A wrong verdict. One mistaken
goodorbadsends the search into the wrong half, and the final commit will look unrelated to the bug. Save the session withgit bisect logand replay it later without the bad answer, as a later chapter shows. - A commit that does not build. You cannot give an honest verdict for it. You can run
git bisect skipto ask Git to pick another nearby commit. - Forgetting the reset. Your next
git statuswill show a detached HEAD.
Why this matters for automation
In the session above you typed the same cycle many times: build, test, report. The only judgment you supplied was good or bad. A script can supply that judgment, and git bisect run can send it to Git for you. That needs an agreed way for the script to answer, which the next chapter covers.
Exercise
A range holds 1,000 commits between a known good commit and a known bad one. About how many tests will a bisect need at most, and which command returns you to your original branch when the session ends?
Show answer
About 10 tests, since log2(1000) is just under 10 and each verdict halves the range. git bisect reset returns you to your original branch.
Exercise
You started a bisect, tested the first midpoint, and found the bug is present. Which command do you run, and which half of the range does Git search next?
Show answer
Run git bisect bad. The bug is present at the midpoint, so the first bad commit is at or before it, and Git searches the older half of the range, between the good commit and that midpoint.