Running Grunt Tasks with Git Pre-Commit Hooks
December 22, 2012I’m always forgetting to run release tasks when committing to git, and then I’m forced to either rewrite history with rebase
or roll back and re-commit. It’s a big time sink. Thankfully, I’ve been playing with Grunt tasks and git pre-commit hooks and found a way to not only save time and my sanity, but take release tasks out of my manual workflow entirely. This hook will stash any work that’s not staged, run the release task, stage any files created or updated by the grunt task and restore any stashed files. If you aren’t using a release task, this will work equally well with grunt jshint
or any testing tasks you may have defined.
In the pre-commit hook (.git/hooks/pre-commit
):
And in your Grunt config:
Never commit linting errors or failing tests again, and let git save your sanity with automated grunt tasks.