Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

githooks

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?

like image 333
slacy Avatar asked Aug 31 '12 20:08

slacy


People also ask

What happens when you git push?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.

Does git push push to all remotes?

Now all fetch and pull operations will only fetch from your original remote repository. But with a simple git push git pushes your latest changes to all remote repositories you've added right now.

Where are git hooks stored?

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .

How are git hooks executed?

The pre-receive hook is executed every time somebody uses git push to push commits to the repository. It should always reside in the remote repository that is the destination of the push, not in the originating repository.


2 Answers

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).

like image 142
Lily Ballard Avatar answered Nov 10 '22 20:11

Lily Ballard


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/.

like image 43
Marco Leogrande Avatar answered Nov 10 '22 21:11

Marco Leogrande