Interview Q&A / Git & GitHub

AdvancedQuick answer1 min readUpdated 3 Oct 2026

How can you automate git bisect with a script?

SHORT ANSWER

Use git bisect run with a command that exits 0 for good and non-zero (except 125) for bad. Git then runs it at each step and finds the culprit commit without manual answers.

Explain it simply

Manually answering 'good or bad' eight times is tolerable; doing it on a flaky project is tedious. A test script can answer for you.

Write a command, such as npm test or a small shell script, that returns exit code 0 when the bug is absent and 1 to 127 when it is present. Exit code 125 means 'cannot test this commit, skip it', useful when a commit does not compile. git bisect run ./check.sh loops until done and prints the first bad commit.

Example

bash
git bisect start HEAD v2.0
git bisect run npm test
# 5d6e7f8 is the first bad commit
git bisect reset

What to say in the interview

"git bisect run takes a script returning 0 for good and 1-127 for bad, with 125 meaning skip. Git then finds the first bad commit by itself. I finish with git bisect reset."

#git#bisect#automation

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.