0

Using Git for a long time now, I'm used to having my config variable specific for each project and some global under ~/.gitconfig. Or same for ~/.gitignore for global exclusion rules depending on my OS.

I'm wondering if something like this is available for hooks. Like a folder ~/.githooks/ that would populate my repositories on init or clone. Or even some hooks that would always trigger before project specific hooks.

I found nothing about this on the Git Hooks documentation. Even if you have a hacky way of doing it I would be interested.

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
  • 2
    When creating a repository you can pass a template to pre-populate things like hooks. Look at `git init --template=`. – Richard Oct 19 '18 at 09:40
  • See also: [Applying a git post-commit hook to all current and future repos](https://stackoverflow.com/q/2293498/94687), [change default git hooks](https://stackoverflow.com/q/1977610/94687) – imz -- Ivan Zakharyaschev Feb 29 '20 at 03:52

1 Answers1

0

This might answer your question, and it is aligned with what @Richard just suggested... there is a step by step inside it.

But this demands you to still handle the hooks in a hard way yet, and they are global, which means you need to worry about that too.

I did a different approach. I want triggers to be global, but not what to trigger. I created this tool: https://pypi.org/project/hooks4git/

It is written in Python, hooks your repo (any repo) with a generic Python code, and interprets a .hooks4git.ini folder which belongs to your project. Inside it, you can reference any script written in any language.

You just need to do a ./hooks4git to hook your repo, just like you need to a do a git init to hook it with global templates.

Hope this helps more.

EDIT1: As pointed by Ulysse BN, here is a better answer to the original question.

Lovato
  • 2,250
  • 1
  • 16
  • 22
  • I really would not want to add something visible to my repository for a hook. However, the first link you gave led me to [this one](https://stackoverflow.com/a/37293001/6320039) more complete that really explains what I want. If you may edit your answer to avoid ending with a rotten link, I'll accept it... Or I'll do it later this weekend – Ulysse BN Oct 19 '18 at 13:01
  • Hi @UlysseBN ... Language Barrier Issue: "to avoid ending with a rotten link" ... I did some editing, but please let me know if I need to do more of it. – Lovato Oct 19 '18 at 13:51
  • I'm saying that your answer is sensible to [link rot](https://en.wikipedia.org/wiki/Link_rot). When including a link you should include it's content as well. There is a good information about that on [so] but I can't remember where... – Ulysse BN Oct 19 '18 at 16:13
  • 1
    Got it. And of course, I agree with that. If you can paste there the right amount of text which actually helped you, I will appreciate. Since I indirectly solved your question, I would be reticent to paste the code which helped you best. And related to the tool I suggested, I cant see a simple way to paste that content here. – Lovato Oct 19 '18 at 17:07
  • As suggested by @UlysseBN there is detailed information around the topic at https://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository – Lovato Apr 23 '19 at 17:56