0
0
Gitdevops~7 mins

git bisect run for automated bisect - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you have a bug but don't know which commit caused it, git bisect run helps you find the exact commit automatically by running a test script on each step.
When you want to find the commit that introduced a bug without manually checking each commit.
When you have a test script that can tell if the bug is present or not.
When you want to save time by automating the bisect process instead of manual testing.
When you have a large number of commits and manual bisecting is too slow.
When you want to integrate bisecting into a CI/CD pipeline for automatic bug detection.
Commands
Start the bisect session to find the bad commit.
Terminal
git bisect start
Expected OutputExpected
No output (command runs silently)
Mark the current commit as bad (contains the bug).
Terminal
git bisect bad
Expected OutputExpected
No output (command runs silently)
Mark a known good commit (e.g., tag v1.0) where the bug was not present.
Terminal
git bisect good v1.0
Expected OutputExpected
No output (command runs silently)
Run the automated test script on each commit to find the first bad commit.
Terminal
git bisect run ./test_bug.sh
Expected OutputExpected
Bisecting: 3 revisions left to test after this (roughly 2 steps) [def5678] Introduce bug Bisecting: 1 revision left to test after this (roughly 1 step) [abc1234] Fix some feature def5678 is the first bad commit Bisecting complete after 5 steps [def5678] Introduce bug
End the bisect session and return to the original branch.
Terminal
git bisect reset
Expected OutputExpected
Previous HEAD position was def5678 Introduce bug Switched to branch 'main'
Key Concept

If you remember nothing else, remember: git bisect run automates finding the first bad commit by running your test script on each step.

Common Mistakes
Not marking a known good commit before running git bisect run
Git needs a reference point where the bug was not present to narrow down the search.
Always mark a known good commit with git bisect good before running the automated test.
Using a test script that does not return correct exit codes
Git bisect run relies on the script's exit code: 0 means good, non-zero means bad. Wrong exit codes cause incorrect bisect results.
Ensure your test script returns 0 if the commit is good and non-zero if bad.
Not resetting bisect after finishing
The repository stays in bisect mode, which can confuse further work.
Run git bisect reset to return to the original branch and clean state.
Summary
Start bisect with git bisect start, mark bad and good commits.
Run git bisect run with a test script to automate checking commits.
Reset bisect with git bisect reset to finish and return to normal.