I have a global git hook post-commit which is situated under:
~/.git_templates/hooks/post-commit
I have made it global by
git config --global init.templatedir '~/.git_templates'
and using git init to update the settings for my git project.
Yet one project had its own post-commit hook under:
~/src/git.repo/.git/hooks/post-commit
The local one ran but prevented the global one from running. How can I achieve that both are run on post commit?
I want to avoid adding the command in the local post commit hook.
You can set a global hook path.
git config --global core.hooksPath "$CONFIG_DIR/hooks"
This will ignore local hook and run global hook scripts only.
And if you want to run both local & global hook, you can call local hook from global hook manually.
For example: call this script from your global pre-commit hook.
...
/path/to/run-local-hook pre-commit
run-local-hook file:
# Run local hook if exists
HOOK=$1
PROJECT_ROOT=$(git rev-parse --show-toplevel)
if [ -e "$PROJECT_ROOT/.git/hooks/$HOOK" ]; then
$PROJECT_ROOT/.git/hooks/$HOOK "$@"
else
exit 0
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With