Are git hooks pushed to the remote when I 'git push'?

GitGithooks

Git Problem Overview


If I create a new hook script in my local repository in repo/.git/hooks/post-commit and then I run "git push" are the hooks pushed to the remote? Then, when the other developers run "git pull" from the same origin will they get my new hooks?

Git Solutions


Solution 1 - Git

No. Hooks are per-repository and are never pushed. Similarly, the repo config isn't pushed either, nor is anything in .git/info, or a number of other things.

Pushing and pulling only exchanges branches/tags and commit objects (and anything reachable from a commit, e.g. trees, blobs).

Solution 2 - Git

No, git hooks are not pushed or pulled, as they are not part of the repository code.

Please refer to the documentation for a list of simple client-side and server-side hooks.

If you want to enable some hooks for all clients that clone or pull from a given repository, you have to add the hooks to your codebase and then create your own script to copy them into, or link to them from repo/.git/hooks/.

Solution 3 - Git

Sadly no but since git 2.9 you can place them into .githooks folder (as others mentioned) and run:

git config --local core.hooksPath .githooks/

So no need of symlinks or copy files.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionslacyView Question on Stackoverflow
Solution 1 - GitLily BallardView Answer on Stackoverflow
Solution 2 - GitMarco LeograndeView Answer on Stackoverflow
Solution 3 - GitMarco MedranoView Answer on Stackoverflow