Use Git Bisect to Find Bugs in Your Codebase

  1. Blogging for Hippo
  2. Schedule Sales with WooCommerce
  3. The Problem with Focus
  4. Give Thanks
  5. Be Thankful for the People Who Inspire You
  6. Give Yourself Space
  7. Build Resources From Support
  8. How Hard Can Membership Be?
  9. Adding Social Media Icons to WooCommerce Product Pages
  10. How to Export WooCommerce Subscriptions
  11. Upgrade Your Contact Form With Ninja Forms
  12. Why I Write
  13. Blog Comments Policy
  14. Content Marketing Works – Even with Furnace Filters
  15. Making Email from Your Website More Reliable with Email Delivery Tools
  16. A Happiness Podcast?
  17. Podcast Compensation
  18. Wishlists Done Right
  19. Enable Free Shipping on a Per Product Basis
  20. Improve Your Writing with the Hemingway Editor
  21. Tell Users What You're Doing
  22. 2014 Business Review
  23. Mind Your Own Business
  24. Think Different to 10x Your Business
  25. Let Projects Die
  26. Maximize Your Creative Energy
  27. Use Git Bisect to Find Bugs in Your Codebase
  28. My Personal Value of Remote Work
  29. Don't Spam Email Receipts
  30. Make Your Own Luck
  31. Cold Showers and the Power of Challenges

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.

Summary

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.

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