Reputation: 26441
I have ~50 repositories on my machine. I would like to install newly created git hook to all of them.
I've already created .git-templates
folder and put hooks there, then git config --global init.templatedir ~/.git-templates
- it works for new repositories but what about existing ones?
Upvotes: 1
Views: 723
Reputation: 60255
Just do it. Find all the repositories and copy the hooks. Here's a sample (this might find more than you think, it's why the actual copy gets echoed not executed, don't just c&p the echoed commands if you might have '
's in your pathnames):
find ~ -name HEAD -execdir test -f config -a -d objects -a -d refs \; \
-execdir mkdir -p hooks \; \
-printf "cp -a ~/.git-templates/hooks '%h'/hooks\\n"
Upvotes: 0
Reputation: 37722
I you use a recent version of git
(>= 2.9), then I would recommend using the core.hooksPath
variable.
Then you can create a separate directory where you put all your hooks, eg /var/myhooks
, then
git config --global core.hooksPath /var/myhooks
would make this directory the default hooks directory for all your repositories at once. As a side effect, all hooks under .git/hooks
in each repository will be ignored. But inside a specific repository, you could then override this again with its own hooks directory:
git config core.hooksPath .git/hooks
Upvotes: 2