Track Down Pesky Bugs with `git bisect`

Tyler Hawkins
Level Up Coding
Published in
3 min readMar 4, 2020

--

Photo by Krzysztof Niewolny on Unsplash

Recently I’ve come across a couple dev issues that were incredibly difficult to track down.

Normally, fixing a bug in JavaScript is as simple as reproducing the issue, viewing the error and the stack trace, finding the appropriate source file, and fixing the code.

But what if the error for whatever reason isn’t helpful? Or what if there is no error? Maybe nothing is technically “broken”, but the behavior that’s occurring in your app is not at all what you expected or intended. Or maybe the error is coming from a third-party dependency that you recently upgraded.

Whatever the case may be, if you aren’t able to easily track down where in your source code the error is coming from, git has a really neat command that can help.

Git Bisect

git bisect is a command that uses a binary search to identify the commit that introduced the issue. Using it is really straightforward.

To begin the process, you enter git bisect start.

Next, you need to identify two commits, one in which the issue exists and one in which the issue does not exist.

So, maybe you’re on your master branch right now with the latest code pulled down, and you’re seeing the bug. So you can tell git that this current commit is bad. To do…

--

--