What is git bisect?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Git & GitHub development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

git bisect is a powerful debugging tool that uses binary search to find the exact commit that introduced a bug. Instead of manually checking each commit, bisect narrows it down in O(log n) steps. Workflow: (1) git bisect start — begin bisect session; (2) git bisect bad — mark current commit as bad (has the bug); (3) git bisect good v1.0 — mark a known-good commit/tag; Git checks out the middle commit; (4) Test whether this commit has the bug; (5) git bisect good or git bisect bad based on the test; (6) Repeat until Git identifies the first bad commit: "abc1234 is the first bad commit"; (7) git bisect reset — return to original HEAD. Automated bisect: git bisect run npm test — run a test script automatically; exits 0 = good, non-zero = bad. Git handles the binary search entirely. Example: a bug was introduced sometime in the last 100 commits → manual check = 100 steps → bisect = ~7 steps. View bisect log: git bisect log. Skip a commit (can't test it): git bisect skip. Bisect is especially powerful when combined with an automated test that reproduces the bug.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Git & GitHub answers easy to follow.