Update

There is a module, called pre-commit, which is working well, and it's easy to set up.

Old way

If you want to write valid code, make sure you use a linter. It's good practice to have some 'on save' linter to tell you what errors you made in the real time. But, besides that, it would be nice to have some tool to lint files when you try to commit them. Git has so-called hooks (actions), which you can trigger at certain points (before you commit, after the commit, before the push, etc.).

My pal Ivan Tatic created script that install git-hook for linting javascript files using jshint. If you try to commit some javascript files, jshint run a check on those files. If there is a file with errors, it prints where you can find those errors.

I created a demo, to show you how it works.