2

I have a git pre-commit hook that checks pep8 compliance, and I want to add it to repositories which have multiple branches already. If I add it to .git/hooks/ on one branch will that hook be present in other branches or is each branches .git folder unique? I want to add the hook to master and have it present in all other branches. Will this require manually replacing it on each branch or can I add it to one branch and have it present in all of them?

ragingSloth
  • 1,094
  • 8
  • 22

1 Answers1

2

It will be active within the repository for all branches. In case of pre-commit hook, all your local branches will have this hook activated before committing stuff.

It will not be active for other repositories, unless it's pre-receive/post-receive (which are server-side hooks that activate on push to repository where the hook is installed).

I tried to find out some documentation to support my statement, but frankly I didn't. Here's some documentation on hooks, but it doesn't tell it outright, that hooks are all common for all branches.

It's pretty straightforward though, because .git directory is unique within whole repository and it is not subject to versioning, it's not a part of the code. When you change hook script it is not visible in not staged changes.

Most people have the opposite problem - to differentiate hooks behavior depending on branch, like Eugene in this question.

Community
  • 1
  • 1
Krzysztof Jabłoński
  • 1,890
  • 1
  • 20
  • 29