Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to propagate Git Hooks while cloning

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?

like image 992
baluchen Avatar asked Sep 03 '25 13:09

baluchen


2 Answers

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.

You can also configure Git to use a different directory for your hook scripts

git config --local core.hooksPath .hooks/
like image 169
iconoclast Avatar answered Sep 05 '25 06:09

iconoclast


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.
like image 26
Kim Ki Won Avatar answered Sep 05 '25 06:09

Kim Ki Won