Store your git hooks in a repository and setup them for all the developers

Gleb Tarasov
1 min readApr 6, 2020

Usually in the company you have some guidelines which git hooks developer should set. But I realised recently, that you can setup your hooks in the repository so every developer will have those hooks automatically. And every change will be picked automatically also.

As the example here I’m setting up the pre-commit hook, but you can set any type with the same trick.

  1. Commit your hooks to your repo. For example, to the hooks folder. Be sure, that your script has permission for execution. Do chmod 755 hooks/pre-commit before commit.
  2. Create your global .gitconfig file in the repo. Execute this command:
git config -f .gitconfig core.hooksPath hooks

3. Commit your new .gitconfig file to your repo.

4. Every user will still need to run this command once after repository checkout:

git config --local include.path ../.gitconfig

And that’s all. If some developer wants to have custom hook, she can overridecore.hooksPath locally.

--

--