Use Git Bisect to Find Bugs in Your Codebase

I've spent most of this week talking about business. But today I really wanted to share a cool tool with you. If you're a fan of using Git on the command line you'll love this. I'm going to show you how to use git bisect to find bugs. It will help you narrow down when exactly a bug was created.

You'll find this very helpful when you start working on repositories that have hundreds of contributors (WooCommerce has more than 300!). Many times it's hard to figure out exactly when a bug was created and with hundreds of commits between releases it's critical you know how to go through them quickly.

Git Bisect

I created a video that shows the whole process. In nine steps and three minutes I was able to go through 500+ commits to find the bug. A bug that I made a couple months ago and had completely forgotten.


You'll have to use git on the command line. If you use some sort of application for managing git repos you'll have to see if this feature is available in your application (I doubt it).

  1. Start the process with git bisect
  2. Checkout a commit with the bug and then use git bisect bad
  3. Next find a tag or commit without the bug and use git bisect good {sha or tag name}
  4. Now go through the steps in git bisect and enter either git bisect good or git bisect bad depending on if you can find the bug
  5. After you're done you can use git bisect reset to end the process

I want to thank Brian Richards for this post. I ran into a bug a few months ago and he suggested this method. I've been using it ever since.

3 thoughts on “Use Git Bisect to Find Bugs in Your Codebase

  1. Ha! Can’t believe I haven’t used git bisect before. Actively looking for a situation to use it now 🙂 Thanks for this Patrick!

  2. I used bisect just the other day to isolate a breaking change in WooCommerce 2.2.9/2.2.10 (screenshot of the bisection).

    I was thinking at the time that a post about using bisect to find breaking changes would be very handy around the WooCommerce v2.3 release – perhaps you can repurpose this then?

    I’d previously only used bisect for diagnosing issues with my code, not isolating compatibility issues by running it to code my code depends on. It works perfectly for that too.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.