Skip to content

git bisect run quick reference

One-line commands and exit codes for automated regression hunting.

Basic run

git bisect start
git bisect bad HEAD
git bisect good v2.3.0
git bisect run ./test.sh

One-liner sequence

git bisect start && git bisect bad HEAD && git bisect good v2.3.0 && git bisect run ./test.sh

With worktree isolation

git worktree add ../bisect-runner HEAD
cd ../bisect-runner
git bisect start && git bisect bad HEAD && git bisect good v2.3.0 && git bisect run ./test.sh
cd - && git worktree remove ../bisect-runner

With first-parent merge handling

git bisect start --first-parent && git bisect bad HEAD && git bisect good v2.3.0 && git bisect run ./test.sh

Path-scoped bisect

git bisect start -- services/payments
git bisect bad HEAD && git bisect good v2.3.0 && git bisect run ./test-payments.sh

Exit code contract

Code Meaning Action
0 Good (passed) Moves to later range
1-124 Bad (failed) Moves to earlier range
125 Skip Tries next candidate
126-127 Script error Aborts

Test script template

#!/bin/bash
set -euo pipefail
npm ci || exit 125
npm run build || exit 125
npm run test:regression && exit 0 || exit 1

Replay a saved session

git bisect log > /tmp/bisect-session.log
git bisect replay /tmp/bisect-session.log

Abort

git bisect reset

CI workflow snippet (Forgejo)

- name: Automated bisect
  run: |
    git fetch origin
    git bisect start
    git bisect bad origin/main
    git bisect good ${{ inputs.good_tag }}
    git bisect run ci/bisect-ci.sh

Aliases

[alias]
    brun  = bisect run
    blog  = bisect log
    bplay = bisect replay

See also

  • docs/devops-workflows/git-bisect-run.md — full advanced guide
  • docs/devops-workflows/git-bisect-ci-triage.md — basic bisect setup
  • scripts/bisect-run-manage.sh — automation script