Skip to content

Bisect

In one line

Bisect uses binary search to find the exact commit that introduced a bug, by testing commits between a known-good and known-bad state.

In simple words

git bisect performs a binary search through your commit history to find the exact commit that introduced a bug. You tell Git a "bad" commit (where the bug exists) and a "good" commit (where the bug does not exist), and Git checks out the middle commit for you to test.

After testing, you mark the commit as good or bad, and Git narrows the search range by half, checking out the next middle commit. This repeats until Git identifies the first bad commit. For N commits, it takes about log2(N) steps.

Bisect is extremely efficient for finding regressions. You can even automate it with git bisect run <command> — Git runs the command at each step and marks the commit good or bad based on the exit code.

Example

bash
# Start bisect
git bisect start

# Mark current (bad) and a known-good commit
git bisect bad
git bisect good v1.0.0

# Git checks out a middle commit — test it
git bisect good  # or git bisect bad

# When done, Git shows the first bad commit
git bisect reset  # return to original branch

bisect binary-searches history to find the commit that introduced a bug.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary