11

I've created a pre-commite hook and it works on my local machine, but I don't know how can I share this hook with my collegs

I will be grateful for any help.

Thanks in advance Denis

Denys Medvediev
  • 1,160
  • 3
  • 16
  • 32
  • Does this answer your question? [Can Git hook scripts be managed along with the repository?](https://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository) – andruso Aug 17 '20 at 14:08

1 Answers1

4

It’s important to note that client-side hooks are not copied when you clone a repository.

On Server side, the 1st hook is pre-receive.

Not everything is possible in this one, depending on what you want to do before the commit, but that's the place to do stuff if you want to do it for everybody who use the repository.

Note: You have to have access to the git server to do that.

Edit:

For global settings, take a look at https://stackoverflow.com/a/8842663/3445619 But this solution requires a new git init to be done by everyone.

If you don't have access to the git server or want to apply code ruler/styler, I would recommend to ask your colleague to make a link from .git/hooks/pre-commit to a versioned file where you can edit your own pre-commit hook for everyone. Or simply share your file with them, if it will never change. (But this will have to be done for every newcomers).

rrawat
  • 1,071
  • 1
  • 15
  • 29
Simon PA
  • 748
  • 13
  • 26
  • I'd like run [jscs](http://jscs.info/overview) before commit. Is it ok to use pre-commit hook in this case? – Denys Medvediev Sep 19 '16 at 11:25
  • yes, pre-commit is exactly the place to execute code styler or code ruler. But using pre-receive assums you already made the commit, thus it is too late to apply jscs. I'll edit the answer for your case. – Simon PA Sep 19 '16 at 11:29
  • Do you have access to you git server configuration ? – Simon PA Sep 19 '16 at 11:43
  • Then follow http://stackoverflow.com/questions/2293498/git-commit-hooks-global-settings/8842663#8842663 to apply your rules to new users. For the current users, i would prefer a versionned *hook* directory in your reposity, then *symbolic link* from your collegues to this hook – Simon PA Sep 19 '16 at 12:18
  • git config --global init.templatedir '~/.git_template' it's not clear enough, can you explain it in more detail, thanks – Denys Medvediev Sep 19 '16 at 12:31
  • The example use *git_template* as a new folder for the new hooks without changing the basic configuration of git. (So the new git repository will not use your new hooks). You can out any name you want here. The command itself will replace all default hooks to the ones in the folder. So if you change the pre-commit hook in this folder, then ask your team to do `git init` this will change the default hooks configuration to the *git_template* you defined. I hope it clear enough, let me know if not. – Simon PA Sep 19 '16 at 12:42
  • I manage to do it partly, I have a problem with separate projects, because those commands (git config --global init.templatedir '~/.git_template' or git config core.hooksPath /path/to/my/centralized/hooks) sets global variables, so they make impediments for each other – Denys Medvediev Sep 20 '16 at 11:12
  • i'm at work right now. If i remember right, there is an environment variable that can be setted to avoid the change to be applied on all the repositories of the server. I will do some research and get back to you later. – Simon PA Sep 20 '16 at 11:25
  • I guess i solved it yourself since you marked the question as "solved" ? You should delete the post with your skype id or it might become nightmare for you if it gets public somewhere ;-) – Simon PA Sep 20 '16 at 14:51