Git bisect: find the faulty commit
A bug appeared but you don't know when? git bisect uses a binary search to automatically find the commit that introduced the problem.
How does bisect work?
A binary search through your Git history. At each step, the search space is halved.
Start
Start bisect and mark a good and a bad commit
Test
Git places you in the middle. Test if the bug is present
Good/Bad
Mark the commit as good or bad. Git halves the range
Found!
After a few steps, Git identifies the faulty commit
Git bisect in practice
Start, test and find the faulty commit.
Start the search
Test and find
Automate bisect with a script
If the bug can be detected by an automated test, bisect can run on its own.
git bisect run npm testGit runs npm test on each commit. If the test passes (code 0) = good. If the test fails = bad. Git finds the faulty commit automatically, without manual intervention.
Part of the Git History, Search & Debug guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git bisect
Practice debugging in GitQuest
GitQuest investigations teach you to track down bugs in Git history like a detective.
Start the investigations