Skip to content

bisect Git Command Guide

The git bisect command uses binary search to find the commit that introduced a bug or regression. It efficiently narrows down the range of commits by marking good and bad commits to isolate the problem.

Terminal window
git bisect <subcommand> <options>
git bisect start <bad> [<good>...]
git bisect good [<rev>]
git bisect bad [<rev>]
git bisect skip [<rev>...]
git bisect reset [<branch>]
SubcommandDescription
startStart the bisection session marking bad/good commits
goodMark commit(s) as good
badMark commit(s) as bad
skipSkip commits that are not testable
resetEnd bisection and return to original branch
run Automate good/bad marking with a script
logShow bisect log
replayReplay a bisect session from log
termsShow current terms (good/bad)
ParameterDescription
revCommit hash or reference
cmdScript or command to run during automated bisect

Start bisecting between known good and bad commits

Section titled “Start bisecting between known good and bad commits”
Terminal window
git bisect start HEAD v1.0

Starts bisect with HEAD as bad and v1.0 as good.

Terminal window
git bisect good

Indicates the current commit is good (bug not present).

Terminal window
git bisect bad

Indicates the current commit has the bug.

Terminal window
git bisect skip

Moves to the next commit without marking good or bad.

Terminal window
git bisect reset

Ends the bisect session and returns to original HEAD.

Terminal window
git bisect run make test

Runs “make test” on each checked out commit and marks automatically.

To start a bisect session, use git bisect start followed by the bad commit and good commit:

Terminal window
git bisect start <bad-commit> <good-commit>

How do I mark a commit as good or bad during bisect?

Section titled “How do I mark a commit as good or bad during bisect?”

During bisect, after checking out a commit, run git bisect good if the bug is not present, or git bisect bad if it is.

To automate, use git bisect run followed by a test command that exits with 0 if good, 125 if skip, or other for bad.

To end the session and return to the original branch, execute git bisect reset.

If a commit can’t be tested, use git bisect skip to move to the next one.

  1. Finding the commit that introduced a bug in the codebase
  2. Identifying regressions introduced in new features
  3. Locating the source of performance issues over time
  4. Debugging when a test starts failing unexpectedly
  5. Narrowing down problematic changes in large codebases
  6. Tracing the origin of security vulnerabilities in commits