Skip to content
A set of useful client side git hooks
Shell Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

MIT Licence Build Status GitHub release Github all releases

Client Git Hooks

A set of useful and generic client side (local) git hooks. To add all of them to your project simply copy the git-hooks directory into the root of your project and then notify Git that this directory is to be used for its hooks. You can do this using the following command;

git config core.hooksPath git-hooks/

The above will only work if you are using Git 2.9 or greater. Otherwise you will need to copy the contents of the git-hooks directory in this project into the .git/hooks directory instead.

Hook Functions Performed

  • Prevent commits including changes with specified strings.
  • Prevent commits including files above a specified size.
  • Prevent commit messages that do not match a specified pattern.

Custom Configuration

The behaviour of these hooks can be changed by specifying custom git configuration. Each function performed by this library of standardized hooks has custom git configuration that can be added.

Excluding specified strings

By default this library will stop any commits that includes the string 'TODO'. If you have added a TODO it is better to register it on a purpose built issue tracking system. This default however may not be to everyone's taste. You can turn this off by adding the following configuration.

git config hooks.allowexcludedstrings true

Or you can specify a file which includes a new-line seperated list of strings that should not be allowed in your commits.

git config hooks.exclusionsfile exclusions.text

Setting maximum file size

By default this library will stop the committing of any files above 1MB. Large files should be dependencies of a project, rather than included in the project itself. Alternatively, some large files can be generated by the build and added to the .gitignore. If you need to turn this feature off you can.

git config hooks.allowbigfiles true

Or if you need to change the maximum file size you can

git config hooks.maxfilesize $x

Where $x is the maximum number of bytes for a file.

Commit message matching regex

By default this library will insist that all commit messages include at least 4 words. You can turn this feature off using the following configuration,

git config hooks.allowcommitmsg true

Alternatively, for more control of your commit messages you can specify the regex the commit messages must match.

git config hooks.commitmsgregex "$x"

Where $x is a Perl compliant regular expression.

You can’t perform that action at this time.