Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking changes to hooks in .git/hooks

Tags:

git

githooks

Is there a way to track git hook changes? I have three hooks that only show up on my machine, not when my other developers fetch. Trying to git add doesn't work.

like image 820
Hans Avatar asked Dec 16 '10 02:12

Hans


People also ask

Are git hooks tracked?

git/hooks is the folder that hosts our customized hooks, but this is not really helpful when we need to share these scripts within the team since this folder is not tracked by git. A good approach for solving this is adding all of our custom hooks on a separate folder inside our repository.

How do I update my git hooks?

update. This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. Just before updating the ref on the remote repository, the update hook is invoked. Its exit status determines the success or failure of the ref update.

Do git hooks get pushed?

No. Hooks are per-repository and are never pushed.


2 Answers

http://benjamin-meyer.blogspot.com/2008/10/git-hooks.html

Files in the .git/hooks directory are not part of the repository and so they are not tracked. A workaround is to have a git_hooks directory at the top of your repository like done in Arora and symlink .git/hooks to git_hooks whenever you clone. This way the hooks will be part of the project, under revision control and accessible to everyone.

like image 151
Brian Clapper Avatar answered Oct 05 '22 09:10

Brian Clapper


I realise this question is years old, but I feel this needs to be said for travellers like myself who wind up here: Hooks are not tracked by design! Brian's answer will work, but the deal with that is that you are effectively trusting everyone else you are working with to not put malicious code in the repository, which your hooks then execute without question; this is the very definition of a security hole.

like image 45
Philip Adler Avatar answered Oct 05 '22 08:10

Philip Adler