Git hooks are a useful feature that can be used to manage the integrity of your source repository, it becomes much handier if the hooks can be shared between team members, as the hooks are localized to once’s device’s single project. Since all the git hook templates reside inside the folder
.git/hooks and it does not track by git versioning system, it’s become a problem to share whatever the hooks you create inside that folder between your teammates. But if you’re using Git version 2.9 or greater, you are in luck, Now you can configure the git hooks path.
Configuring Custom Git Hook Path
In order to share the custom hooks that you created, with your team; you can create a separate folder inside your project and add all the hooks there first. In my case, I created a folder called
.githooks in my project root directory. Then I placed my custom hooks (i.e pre-commit, com, prepare-commit-msg, commit-msg, etc) inside that folder. Then this folder will be automatically tracked by the git versioning system.
Next, we should update the configurations in order to let the git knows where our hook files lie, To do that you can execute the following command inside your root directory.
git config core.hooksPath .githooks
This command will set the git hooks location to new
.githooks location, then your teammates also can update the same config for the location of the hooks, this way all of the teammates can access the updated version of hooks.
I hope covered every basic thing you need to know in order to share the git hooks between teammates, if you have any more questions related to this article, feel free to ask anything in the comment section below. Cheers!!