Use gruntjs as precommit hook

Is there a way to run a gruntjs task as precommit hook. For example I want do prevent commits with failing tests or jshint issues. I’ve also think about to run a code beautifier for every commit.

  • git ignore for directories with spaces on Mac OS X
  • 10 GIT lines erased 8Gb form my pc - How to get them back?
  • How to linearize “splintered” merging history in Git?
  • cannot run hooks/post-update: No such file or directory
  • When would you use .git/info/exclude instead of .gitignore to exclude files?
  • Git: Internal error: refs/remotes/origin/master is not a valid packed reference
  • Using .gitignore to not commit bin, debug and config folders
  • What to ignore in Git with Cowboy / project?
  • Installing GitWeb - How to
  • How do I setup DiffMerge with msysgit / gitk?
  • Could not execute editor
  • How do I get a particular feature branch from origin?
  • 3 Solutions collect form web for “Use gruntjs as precommit hook”

    Git hooks are just scripts executed when you do an action like commit. They can contain whatever programming language you’d like.

    Example of triggering grunt:


    Save this in the file: .git/hooks/pre-commit

    If grunt exits with an error code higher than 0, which it does if any task fail, it will prevent the commit:

    Exiting non-zero from this hook aborts the commit

    Reading material:

    And the git docs:

    Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur.

    I recently had the same issue and detailed a more comprehensive Grunt solution on

    I think you should check out grunt-githooks, a nice Grunt plugin that does all the magic for you and lets you easily register Grunt tasks for certain hooks from within your Gruntfile.js, such as:

      githooks: {
        all: {
          // Will run the jshint and test:unit tasks at every commit
          'pre-commit': 'jshint test:unit',

    (Taken from the docs at

    Find the module on npm here.

    Git Baby is a git and github fan, let's start git clone.