Our project is on a server which is running as a git server. We are running on Windows machines to interact with that server. I am in the process of developing a pre-commit git hook. The first question is whether git will look for that hook in the user's forked repo .git/hooks folder only, where he/she is doing their edits and commit, or whether it will look in the "parent's" (project) .git/hooks folder only? If its the former, can a separate script of some sort be developed that will copy the "latest-and-greatest" hook into the user's repo .git/hooks folder regularly to ensure they are running the right thing?
Asked
Active
Viewed 107 times
1 Answers
0
Git looks for hooks only in the local repositorys .git/hooks
folder. The .git
folder is not part of the repository, so you cannot directly deploy hooks to other developers machines. Which is totally fine, since you don't want repositories to be able to run arbitrary code without you noticing.
Some possible mechanisms to deploy hooks are discussed in this question.

kowsky
- 12,647
- 2
- 28
- 41
-
The real context of the question relates to the fact that our repos are on their own server, akin to GitHub. Many of our users fork the master, but make their changes to the resources from a GUI on that server, and then doing the add and commit there. I can see neither the .git\hooks on my server fork or on the master fork. I know that the .git folder is non-visible (by default) with its contents not under CM. My question then is how can I set up git hooks for work done on the server, and somehow be able to "manage" those if updates are needed to the hooks? – DaveS Sep 06 '18 at 14:30
-
I’ve re-read your 1st sentence and there is a definite inference that no hooks are supported on the server. That means I’ll have to run a gitwhatchanged against the server master every morning and then syntax check those that were changed the day before. That’s putting the checking later in the cycle, but Oh well. – DaveS Sep 07 '18 at 01:57
-
Well, I wouldn't say that `no hooks are supported on the server`; my answer may have been misleading here. There are server-side hooks (see [here](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)), but as far as I understand, none of those will resolve your question, since you have no way to modify the contents of other repositories `hooks` folders. – kowsky Sep 07 '18 at 05:39