3

I was wondering if 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!

3
  • The hook scripts are all local to a specific repository. Commented Jan 29, 2015 at 20:40
  • 1
    Is there some setting I can configure in the .gitconfig file to force a hook script to run on commit? Commented Jan 29, 2015 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... Commented Jan 29, 2015 at 21:04

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.