Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Git hook scripts be managed along with the repository?

Tags:

git

githooks

We'd like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored under <project>/.git/hooks/. However, those scripts are not propagated when people do a clone and they are not version controlled.

Is there a good way to help everyone get the right hook scripts? Can I just make those hook scripts point to version controlled scripts in my repo?

like image 365
Pat Notz Avatar asked Jan 09 '09 06:01

Pat Notz


People also ask

Are git hooks stored in the repo?

By default hooks are stored in . git/hooks outside of the working tree and are thus not shared between users of the repository. The hooks can be included in a directory within the repository and then each developer can set Git up to use them.

Are git hooks version controlled?

git/hooks directory isn't cloned with the rest of your project, nor is it under version control. A simple solution to both of these problems is to store your hooks in the actual project directory (above the . git directory). This lets you edit them like any other version-controlled file.

Are git hooks synced?

Unfortunately, git doesn't automatically synchronize hooks between project contributors.


1 Answers

In Git 2.9, the configuration option core.hooksPath specifies a custom hooks directory.

Move your hooks to a hooks tracked directory in your repository. Then, configure each instance of the repository to use the tracked hooks instead of $GIT_DIR/hooks:

git config core.hooksPath hooks 

In general, the path may be absolute, or relative to the directory where the hooks are run (usually the working tree root; see DESCRIPTION section of man githooks).

like image 80
Max Shenfield Avatar answered Oct 26 '22 22:10

Max Shenfield