Git & GitHub Interview Question #121

What is git bisect?

Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced

Quick Interview Answer

git bisect helps locate the commit that introduced a regression by performing a binary search through commit history. You mark a known bad commit and a known good commit, then test the commits Git selects.

Detailed Explanation

git bisect helps locate the commit that introduced a regression by performing a binary search through commit history. You mark a known bad commit and a known good commit, then test the commits Git selects.

After each test, mark the selected commit good or bad until Git identifies the first bad commit. Automated tests can make bisect especially effective for reproducible regressions.

Code Example

git bisect start
git bisect bad
git bisect good <known-good-commit>

# Test the selected revision, then:
git bisect good
# or
git bisect bad

# Finish
git bisect reset