Open In App

Git bisect

Last Updated : 11 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

When a bug appears in your project, it is hard to figure out which commit caused it especially if there are hundreds of changes. Manually checking each one is slow and frustrating. Git Bisect solves this by using binary search to quickly find the faulty commit. You just mark one commit where everything worked (good) and one where the bug exists (bad), and Git automatically checks the commits in between to narrow it down saving time and effort.

What does the git bisect command do?

git bisect is a command in Git that helps you find the commit that introduced a bug or caused a regression in your codebase. It uses a binary search algorithm to efficiently narrow down the range of commits that needs to be tested.

By marking specific commits as “good” or “bad”, git bisect automatically selects the next commit for testing until it identifies the exact commit that introduced the issue. This process helps identify the faulty commit more quickly and efficiently, enabling developers to pinpoint and fix the problem more effectively.

Implementation of Git bisect command

Let’s say you have a repository where you found a bug in the code. Here is how you would implement git bisect step by step:

Step 1: Start the bisect process

git bisect start
file

Step 2: Mark the current commit as bad

Assume HEAD is the bad commit

git bisect bad
file

Step 3: Identify a known good commit

Replace <good_commit_hash> with the actual hash of the last known good commit

git bisect good <good_commit_hash>
file
file

Step 4: Test each commit

  • Git will now check out a commit in the middle of the range. Run your tests:
  • Run your test command
./run-tests.sh  
  • If the tests fail (bug is present):
git bisect bad
  • If the tests pass (bug is not present):
git bisect good

Step 5: Repeat until you find the offending commit

Git will continue to provide you with commits to test. Follow the previous step until you see a message indicating which commit introduced the bug.

Output:

file

Conclusion

git bisect is a highly efficient and practical tool to track down bugs in your Git history. By combining automation with binary search logic, it drastically reduces the time needed to identify the commit that introduced an issue making debugging in large projects far more manageable.


Article Tags :

Similar Reads