tags:

views:

519

answers:

1

I've written a Git post-commit hook and it works correctly. However, I want to add this hook to apply to all current (and future) git repositories I am working on. I tried adding the hook to my ~/.git/hooks/ instead of in the hooks directory in the project directory, however, this did not seem to work.

Is there any way to create global Git hooks that will apply to all repositories on my system (without having to copy them into each project directory)? If not, what would be the best solution going forward -- perhaps a git-init template?

+7  A: 

If you want them everywhere on your system (including users besides you), you can modify the contents of the installed template directory - those are in $PREFIX/share/git-core/templates/hooks, where $PREFIX is probably /usr/local or /usr.

If you want this to just be for you, then yes, the simplest thing would be the --template option of git-init. You could easily keep a personal template directory which has symlinks back to the installed version of defaults you want to keep (individual hooks, the info directory...) and then your own content in hooks/post-commit and anything else you want to customize.

Jefromi
Thanks, this worked out well. And to retroactively apply it to my existing projects, I just ran `git init` again and it added my new hook.
swanson