← Back to Git Course | Chapter 6: Advanced Commands | Lesson 4 of 7

Git bisect Command

Starting Git Bisect

git bisect finds the exact commit that introduced a bug using binary search instead of checking commits one by one. You start it with git bisect start, then mark your current commit git bisect bad and a known-working older commit git bisect good <hash> to define the search range.

Example: Starting Git Bisect

bash
git bisect start
git bisect bad
git bisect good v1.0

Marking Commits Good and Bad

After you mark the range, Git checks out the commit halfway between good and bad and waits for you to test it and report back with git bisect good or git bisect bad. Each answer halves the remaining range, so a bug hiding among a thousand commits typically takes under ten steps to isolate.

Example: Marking Commits Good and Bad

bash
git bisect good
git bisect bad

Automating with Bisect Run

Manually testing and reporting at each step is tedious for a bug with an automatable check — git bisect run <script> lets Git test each commit itself, treating a zero exit code as "good" and non-zero as "bad," and it will run to completion and report the culprit commit unattended.

Example: Automating with Bisect Run

bash
git bisect run ./test.sh

Resetting the Bisect Session

git bisect reset ends the session and returns your working directory to the branch and commit you were on before you started — skipping this step leaves you stranded on whatever commit the bisect last checked out, in a detached-HEAD state.

Example: Resetting the Bisect Session

bash
git bisect reset

Viewing Bisect Log

git bisect log prints every good/bad judgment you made during the session, and that same output can be fed back into git bisect replay to rerun an identical bisect on another machine or after pulling new commits — handy for sharing a reproducible investigation with a teammate.

Example: Viewing Bisect Log

bash
git bisect log
git bisect replay bisect-log.txt
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.