29

I've written a pre-commit hook in my central repository. When my clients clone the repository it never propagates the hooks. I would like the hooks to also be copied to my clients' repositories. My clients are Windows users, using msysgit as the git client.

Is there any way I can get the hooks copied to local repositories?

iconoclast
  • 21,213
  • 15
  • 102
  • 138
baluchen
  • 749
  • 3
  • 11
  • 18
  • 1
    possible duplicate of [Git hooks - propagating from remote repository?](http://stackoverflow.com/questions/3471028/git-hooks-propagating-from-remote-repository) – rtn May 12 '11 at 10:28
  • 3
    possible duplicate of http://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository (although the symlink suggestion may not work on Windows...) – Mark Longair May 12 '11 at 12:19

2 Answers2

11

You could write a setup script, e.g. setuphooks.sh, that pulls down the hook scripts and installs them in the right places. It shouldn't be hard to write, as curl could do most of the work.

Or you could just include the hooks in the repo in a normal folder like .hooks, and copy them all to .git/hooks.

Others have suggested you symlink them, but that poses problems for users of Windows.

iconoclast
  • 21,213
  • 15
  • 102
  • 138
10

Simple way, but half method. ;-)

I'm using Git on Windows.

  1. Find the folder where git is installed.
  2. Find the sub-folder "share\git-core\templates\hooks"
  3. Copy the hook scripts there that you want. That folder contains hook script samples, generated in new Git repos by the git init command.
  4. If you use the git clone command then the hooks folder contains the files that you copied on step 3.
iconoclast
  • 21,213
  • 15
  • 102
  • 138
Kim Ki Won
  • 1,795
  • 1
  • 22
  • 22
  • That's pretty cool, thanks! Note that the same folder in Linux is located under `/usr/share/git-core/templates/hooks`. – hoefling Dec 01 '15 at 15:19
  • 1
    what does the sentence `I'm used in Windows Git.` mean? I'm sure there's a typo in there, but don't know exactly what you meant – knocte Jan 08 '16 at 03:30
  • I guess it is the same to say " I am using git on Windows" – Flows May 26 '16 at 11:30