Locate the Commit That Introduced a Regression with Git Bisect
Use git bisect to binary-search commit history and pinpoint the exact commit that introduced a bug or regression.
24 Sept 2026, 15:24 UTC

What this solves
Your application worked in an earlier release but fails now, and you need to know which change caused the regression. Inspecting commits one by one is slow. Git bisect performs a binary search across commit history: you mark one commit as bad and an earlier commit as good, Git checks out a commit between them, you classify that commit as good or bad, and Git repeats until it names the first bad commit. When the session is finished, run git bisect reset to return to your starting branch.
Before you start
- A local Git repository with a working tree you can modify.
- A known bad commit, usually the current HEAD where the bug is present.
- A known good commit, such as a previous release tag or earlier commit hash where the bug is absent.
- A repeatable check—a test suite, build script, or manual steps—that reliably classifies each commit as good or bad.
- A clean working tree, or committed or stashed changes, because git bisect checks out old commits and can overwrite uncommitted work.
No special permissions are required beyond normal read and write access to the local repository.
Start the session and mark endpoints
Open a terminal in the repository root and start the session:
git bisect start
Mark the current state as bad. This defaults to HEAD:
git bisect bad
Use git bisect bad <commit-hash> if the bad commit is not the current checkout.
Mark an earlier commit as good, replacing the placeholder with a tag, branch name, or hash:
git bisect good v1.2.0
Git checks out a commit roughly halfway between the good and bad commits.
Test each midpoint and mark the result
- Run your repeatable check on the commit Git has checked out.
- If the bug is absent, mark the commit good:
git bisect good
- If the bug is present, mark the commit bad:
git bisect bad
- Repeat the previous two steps. Git checks out another midpoint each time. When Git has enough information, it prints the first bad commit and its hash.
- Inspect the identified commit, replacing the placeholder with the reported hash:
git show <first-bad-hash>
- End the session and return to your original branch:
git bisect reset
Automate with git bisect run
If you have a script that exits with status 0 when the bug is absent and a non-zero status when the bug is present, let Git run it automatically:
git bisect run ./regression-check.sh
The script must be executable and deterministic. This example is a placeholder; replace the test command with your project's actual check:
#!/bin/sh
# Placeholder: replace with your project's build or test command
if ./run-regression-test.sh; then
exit 0
else
exit 1
fi
| Exit code | Meaning for git bisect run |
|---|---|
| 0 | Commit is good |
| 1-127, except 125 | Commit is bad |
| 125 | Skip this commit |
Core bisect behavior is stable in current Git releases; very old versions may format output differently. Do not use this automation with flaky tests, because nondeterministic results invalidate the binary search.
Confirm the result
- Review
git bisect logto confirm the good and bad decisions Git recorded. - Verify the identified commit with
git show <hash>and reproduce the issue at that revision. - Confirm the issue is absent at the parent commit, for example by temporarily checking out
<hash>^or reviewing the diff introduced by<hash>. - Run
git bisect reset, then confirm withgit statusandgit log --oneline -1that you are back on the original branch and HEAD.
Abort or correct a session
git bisect changes the working tree by checking out old commits, so it is a state-changing operation.
- To review decisions, use
git bisect log. - To reapply a recorded session, save the log to a file and use
git bisect replay <file>. - To mark a commit untestable, use
git bisect skip. Too many skips can prevent Git from identifying a unique first bad commit. - To abort at any time, run
git bisect reset. This returns HEAD to the original position, but it does not protect uncommitted changes made during testing. Commit or stash those changes first if you need to keep them.
Limits of this method
- The bug must follow a monotonic pattern: present at the bad commit, absent at the good commit, and introduced exactly once in between. Flaky tests or intermittent bugs break this assumption.
- Do not bisect across rewritten or force-pushed history; changed commit identities can mislead the search.
- Avoid leaving a bisect session open on shared branches that others are integrating, because old checkouts can confuse concurrent work.
Check that you found the right commit
A practical way to check the result is to build or run the failing scenario at the identified commit, then repeat it at the parent commit. If the bug appears at the first bad commit and not at its parent, you have found the change that introduced it.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.