Standardize git hooks across a repository
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
If you have a need to standardize git hooks for a cloned repository, this Knowledge Base Article will describe how to include the git hooks into your repository and configure git to use them. For more information on git hooks, please see the Atlassian git hooks Tutorial.
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
Environment
This is for any git repository. To implement this article please ensure that only git version 2.9 or greater is used.
Solution
Use a convention in your organization on where to put the git hooks. This particular example will use .githooks. Inside the .githooks directory, put all of your currently used hooks. Then commit this directory to your repository and make sure it is executable. Once the hooks are in the repository, each user using the repository can run the following command to be configured to run the hook:
1
git config core.hooksPath .githooks
Or, you can also include the git config in the repository. For this example we will use .gitconfig. The users will need to run this command to configure git to use the local config file assuming the working directory is the root of the git repository:
1
git config --local include.path ../.gitconfig
Then create this .gitconfig file with the following contents:
1
2
[core]
hooksPath = .githooks
Was this helpful?