Synopsis
git bisect start
git bisect good <commit>
git bisect bad <commit>
git bisect run <script>
git bisect reset
Description
The git bisect command performs a binary search through commit history to identify exactly which commit introduced a bug. You start by marking a known-bad commit (often HEAD) and a known-good commit (perhaps a release tag), then Git checks out a midpoint and asks you to test. You answer "good" or "bad," Git narrows the range, and you repeat until the offending commit is found.
If you have an automated test or reproducer, git bisect run automates the entire process — Git invokes your script at each step. Bisecting through a thousand commits typically takes about ten iterations.
In day-to-day use, git bisect integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git bisect --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git bisect interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git bisect's side effects helps avoid all three.
Common Options
| Subcommand | Description |
|---|---|
start | Begin a bisect session. |
good / bad | Mark the current (or specified) commit. |
skip | Mark a commit as untestable. |
run <cmd> | Automate by running a command (exit 0 = good, non-zero = bad). |
reset | End the session and return to the original branch. |
log | Show the bisect log. |
visualize | Show remaining suspect commits. |
Examples
git bisect start
git bisect bad HEAD
git bisect good v1.5.0
# Git checks out a midpoint; test it, then:
git bisect good # or: git bisect bad
git bisect run npm test
# Fully automated: npm test exit codes drive the search
git bisect reset
# Return to your original branch
Common Mistakes
Forgetting to git bisect reset leaves you in a detached HEAD state. Marking a commit "good" when the bug is intermittent leads bisect astray — use skip instead. Make sure your test script returns exit code 125 to signal "skip" if the build itself is broken at that commit.
Related Commands
git log, git blame, git show, git checkout