user6329667
user6329667

Reputation: 517

Git hook automatic installation

I am working in big project with many repositories with many branches and people who works with them. We have commit message standard but people are people and sometimes make this commit massages incorrect. That's why i create a git commit hook and now i need some how to install it on all users local repositories.

So the question is it possible to install this commit hook automatically not to ask users about it?

Upvotes: 19

Views: 9384

Answers (2)

Jason Greathouse
Jason Greathouse

Reputation: 179

export GIT_CONFIG_PARAMETERS="'core.hooksPath=.githooks'"

This will run hooks stored in .githooks relative to your current repo.

Set this in your shell rc file and assuming you standardize on storing your hooks in a '.githooks' directory you won't have to set git config or link files in every repo.

Gotchas

The "danger" here is someone could put something malicious in a hook, but hey you checked before you cloned their repo right?

Upvotes: 4

larsks
larsks

Reputation: 311506

So the question is it possible to install this commit hook automatically not to ask users about it?

It's not. Being able to automatically install scripts on a machine that will run without any intervention from the user is a substantial security issue, which is why there is no facility to do this.

There are a few things you can do:

  • Provide a script in the repository that will configure your git hooks, and provide instructions to run the script after cloning the repository.

  • Implement enforcement policies on your git server, so that if someone tries to push a change that doesn't meet your standards it will be rejected. This will encourage people to install your local hooks.

Upvotes: 17

Related Questions