git pre- and post- commit hooks not running

In my case core.hooksPath in projRootDir/.git/config was set incorrectly. Removing the entry from config file did the trick


I have seen for instance the config core.hooksPath being set to another path than $GIT_DIR/hooks, making your hooks in that folder ignored.

Check your git config core.hooksPath output, and more generally git config -l for any out of the ordinary settings.

Note that a git commit -n would skip the pre-commit hook.

Edit by wolever:

I've added this to the scripts in my core.hooksPath directory, which will run the repo's hooks if they exist:

#!/bin/sh
set -eu
hook_name="$(basename "$0")"
hook_script=".git/hooks/$hook_name"
[ -e "$hook_script" ] && "$hook_script"
exit 0

Tags:

Git