Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

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.

1

Start

Start bisect and mark a good and a bad commit

2

Test

Git places you in the middle. Test if the bug is present

3

Good/Bad

Mark the commit as good or bad. Git halves the range

4

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

Tip

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 test

Git 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

A

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