DEV Community

Cover image for Useful "advanced" commands in 2 minutes - Git Bisect
Antonio Djigo
Antonio Djigo

Posted on

Useful "advanced" commands in 2 minutes - Git Bisect

Hey ๐Ÿ‘€โœจ

Welcome to Useful "advanced" commands in 2 minutes. Let's be quick about this. Have you ever introduced a bug, and noticed 5 commits after, without knowing where did you put added that bug to the code?

That's where git bisect will help you (a lot!).

Let's GO

So, how does this work?:

First, you need to go to the last commit where you have this bug present somewhere around the code, let's say you are in the master branch.

Then you are going to write in your console:

git bisect start

Nothing will happen after you tell the system the hash of the commit that has the error, by saying:

git bisect bad hashofthebadcommitas489sf0

and you also need to tell the system a commit where the code was working as expected, like:

git bisect good hashofthegoodcommiteoiwi30ea

Bisect then will prompt a message like this:

Bisecting: 3 revisions left to test after this (roughly 2 steps)
[cc6a1e3f00cf5360c3bae687fdcf21f1c111accd] Commit message that you wrote

Now, it's time to test, go to that part of the website/app where you have the error, and check whether you still have the error or not.

If you don't have the error, you will write git bisect good, if you DO have the error, write git bisect bad

Bad boy bisect

After you choose one of these options, git bisect will automatically checkout to another commit, where you'll have to do the check again, is everything good? bisect good, else, bisect bad.

Until you reach the last possible commit to check, where, after you make the last decision, git will tell you this.

ed4d268d1ec7039bc6b5e4ee7c4ce28sbc3af30 is the first bad commit
commit ed4d268d1ec7039bc6b5e4ee7c4ce28sbc3af30
Author: Antonio Djigo <>
Date: Tue Mar 10 11:59:06 2020 +0000

Add new functionality where for sure I won't break anything

And there you have it! Now you know which commit was the first one that introduced the bug, so you can fix it ASAP!


You can follow me so you are tuned to whenever I post something through my Twitter account, hope you liked it!

Top comments (0)