2

I was wondering fi there was a simple way to set up a post commit git hook so that it would run regardless of the repo that it is run with (It is my understanding that the applied hook comes from a hook/ folder in the git directory).

Thank you!

Zubatman
  • 1,235
  • 3
  • 17
  • 34
  • The hook scripts are all local to a specific repository. – twalberg Jan 29 '15 at 20:40
  • 1
    Is there some setting I can configure in the .gitconfig file to force a hook script to run on commit? – Zubatman Jan 29 '15 at 21:00
  • Not that I am aware of. But you could write your own script called e.g. `git-mycommit` that does whatever hook-like things you want and then ultimately calls `git commit`, and as long as it is in your `PATH` somewhere, you can call it as `git mycommit` (`git` will search for alternative commands named `git-foo` when an unknown `git foo` subcommand is given to it). Of course then you have to train yourself (and everyone else) not to use `git commit`, but to use your custom command instead... – twalberg Jan 29 '15 at 21:04

1 Answers1

3

This actually has a relatively simple answer, but it was a nightmare to find. Here's the terminal commands I used to do it, it works perfectly.

git config --global init.templatedir '~/.git-templates' mkdir -p ~/.git-templates/hooks cp post-commit ~/.git-templates/hooks/ chmod a+x ~/.git-templates/hooks/post-commit

In this example post-commit is an executable bash script

Zubatman
  • 1,235
  • 3
  • 17
  • 34