How to share Git Hooks

Some time ago I wrote how to create Git Hooks for your project. What I didn’t wrote about is how to share these Git hooks with your team. If you don’t know how to create Git hooks yet, then I recommend reading the blog post below first.

Step 1 – Create folder inside project

First lets create a separate folder inside your project and add all the hooks there. In my case, I created a folder called .githooks and placed it in the root directory of my project. Then it’s just a case of placing all the Git Hooks inside this folder. Make sure to commit this folder and files into Git, otherwise all would be for nothing.

Step 2 – Configure Custom Git Hook Path

Next, we should update the configurations in order to let Git know where our hook files are located. 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. That’s it, you are all set. But not your teammates let’s do the final step to be fully done with this.

Step 3 – Share the command

Let your teammates pull your changes and also execute the command. This is because their git configurations were not configured yet.

I would recommend to also point this out in a file for the next developer that joins the project. In my case, it’s part of the onboarding checklist.

Happy coding!

Add a Comment

Your email address will not be published.