Explain Binary Search in the context of git bisect

So this morning when I logged on, I did my regular checkout of our codebase's latest upstream and merged that to my local. I brought it in, re-installed the dependencies and ran our app and, my feature crashed. It did not precisely crash, but it entered this infinitely loading and re-loading cycle that it could not get itself out of.

The features were fine yesterday when I finished. So something must have been wrong in between the earlier point my code was based on, and the newest code that I just merged in. So I had been trying to find out what happened.

There were about 30-something commits between then and now. From one of them onwards, it went bad. So I did a "binary search". This is a process similar to a strategy you might adopt when you are trying to guess a number. Say I ask you to guess a number between 1 and 100. A strategy you can use is to always halve the range to narrow down your guess. So you say 50, I tell you too small. Then you go 75, too big. And so you take the midpoint again, so on so forth, until you hit the number. You can narrow down your search very fast this way.

So I'm doing something similar here. I look at the 30 commits, before all of them, things were good. After, bad. I approximate a midpoint, go to that commit, install all the dependencies, and run the app, still good. OK that means the bad commit is after. Then I take the midpoint of the second half, go to that commit, re-install all dependencies, and run the app. Now it's bad. Then I narrow down in that half again.. Note how it's important that I need to narrow down with fewest iterations possible because every one of my guess comes with a cost. To re-install the dependencies and re-run the app takes a good few minutes, so I have an incentive to repeat as fewest as possible. Luckily, with this manual process, after about two iterations, I saw one commit that looked suspicious which says "React 18 upgrade". So I went to before that commit--good, and to that commit--bad. And I found my criminal.

There's actually an automated command by git that does exactly this--git bisect (doc).