Ever accidentally commit some code, push it, and then find out that there were failing specs? Ouch, me too. I’ve got some good news, though: Git has the ability to run a script before it allows code to be committed through Git Hooks. With this ability we can run our specs before the code is committed and only the commit if the specs pass.
In every git project you can edit the
pre-commit-hook by editing
Here’s my pre-commit hook:
1 2 3 4 5 6 7 8 9 10 11 12 13
This fairly small script checks the current branch, saves it to a variable and the only runs the specs if we’re on master. If the specs fail then a message is output, otherwise the code is committed.
One last thing, you can skip running the specs and commit like this:
git commit --no-verify