Find Regressions Like a Boss with Git-bisect

Git bisect is a powerful tool to run any script with a binary search to check for regressions in application code


A few days back, our little dev team of 3 had to figure out where a regression was introduced within approximately a 30 commit window. RSpec was passing, but our cucumber test runner was failing. Our Cucumber suite takes around an hour to run (don't even get me started), so we didn't really know where to start to figure out where the build broke. Luckily, our Jenkins build lets us know which specific cucumber features were failing, so all we needed to do was run one of those features against specific commits. But manually running those cukes against (potentially) 30 commits sounded pretty nightmarish. So that's where git-bisect worked it's magic.

In short, git-bisect does a binary search through your commit history to help identify a troublesome commit. The command sequence looks some like this:

$ git log # select a starting point where your spec suite was passing
$ git bisect start
$ git bisect good <paste good commit>
$ git bisect bad <paste bad commit which can be HEAD> 
$ git bisect run cucumber features/your-file.feature -r features/* # will run your script against each commit

If you want to read more about git-bisect, here ya go.

Here's git-bisect in action:


Some additional helpful commands:

$ git bisect visualize # GUI for viewing progress of the git bisect
$ git bisect run <insert testing script> # i.e. git bisect run cucumber --tags @active