How to find a bug with git bisect

Finding an old bug can be tricky and take some time, especially when you are working on a big project with a lot of commits. Most of the time, you need to define what commit introduced the bug to be able to fix it efficiently. If you have 100 commits to go thought it can take a while. Luckily for you, git has a command that can help you isolate the bad commit faster. This is how to find a bug with git bisect.

You will need to give it the id of the commit where you know there is no bug. And then start it on the interval of this good commit and your HEAD with the commit.

git bisect start HEAD c78fde8

Here the bisect will cut the number of commits in two, and start on the second half. You will be able to test the current commit and then run either good if there is no bug :

git bisect good

Or bad if there is one.

git bisect bad

If you are not sure use :

git bisect skip

Depending on your answers good and bad, it will continue to roll a list of commits until it will give you the number of the first commit containing the bug. Nice right?!

If you want to quit the bisect you can use :

git bisect reset

Hope I could help.

To learn more about git checkout my git cheatsheet

git cheatsheet image
TheTrendyBrand