Git hooks : applying `git config core.hooksPath`
The core.hooksPath
support is new in Git version 2.9, having been put in with commit 867ad08a2610526edb5723804723d371136fc643
. If your Git version is not at least 2.9.0, setting a hooks-path variable will have no effect at all.
Related videos on Youtube

Nicolas Marshall
Fond of the open-source based web, I'm interested in crafting innovative products with care for the user experience. Obsessed with code performance, I love coding reusable and maintainable and keeping updated with the latest languages and tools.
Updated on September 06, 2020Comments
-
Nicolas Marshall over 2 years
I have a git repository with a pre-commit hook set up :
my-repo |- .git |- hooks |- pre-commit # I made this file executable
Until there, everything works. The hook is running when I commit.
=================================
I now run
git config core.hooksPath ./git-config/hooks
inmy-repo
.The folder structure is this one :
my-repo |- .git |- hooks |- git-config |- hooks |- pre-commit # I made this file executable as well
What happens is :
- the new pre-commit script doesn't run on commit
- the old pre-commit script still runs on commit if I leave it in
my-repo/.git/hooks
- running
git config --get core.hooksPath
inmy-repo
outputs./git-config/hooks
How can I make the new pre-commit hook run on commit ?
Here's the link to the docs I apparently don't understand well :
https://git-scm.com/docs/git-config
https://git-scm.com/docs/githooks-
Xerri about 5 yearsTrying to implement
core.hooksPath
myself. Will the default fit hooks be run in addition to you custom hooks or will only your custom hooks be run? -
Nicolas Marshall about 5 years@Xerri The
core.hooksPath
option overrides the default value (./.git/hooks
) so only the hook scripts in the new folder you specified will be detected and run.
-
Nicolas Marshall over 6 yearsHmmm I can't believe I didn't check that before ! Anyways, that was it, I updated git and it works perfectly. Thanks !
-
torek over 6 years@onmyway133: hooks are kind of a pain, as there are about 40 gazillion ways to prevent them from running, and Git says absolutely nothing when any one of those ways does the preventing. So you must enumerate all the ways that hooks fail, checking each one in turn: (1) can Git find it? (2) is it executable (chmod +x)? (3) is it really executable (#! interpreter line if needed)? (4) is it really really executable? (ACLs, etc) ...
-
iomv almost 2 yearsThanks @torek, your comment should be a response on its own as it saved my time since I forgot to make it executable
-
Guian over 1 yearMy hooksPath setting is stil ignored... having updated git to 2.33 ... I've created symlinks from .git/hooks to the actual path but I'd rather get it working ...
-
torek over 1 year@Guian: so when symlinked into place, the hook files work, but when referred-to via
core.hooksPath
, they don't? That's a bit odd; look into any OS specific weirdness, such as limiting exec() across file systems for instance. (This will depend highly on your OS, ACLs, etc.)