I have a script on the client machine that adds the necessary configuration stuff to gitosis.conf on the server. I'm able to push and everything works correctly.

However, I want to add a post-receive hook so that when the repository is first pushed, some particular action occurs. I tried to add it to the local repository before the first version (in .git/hooks) but the hook wasn't transferred to the server on a push.

How can I do this? There is no repository in the /srv/gitosis/repositories directory until the initial push.


Git uses templates to set up new repositories. I don't know if Gitorious uses these same templates, but it's worth checking out. On my system they exist at /usr/local/share/git-core/templates/hooks.

  • I checked out the gitosis documentation and it's extremely sparse. Is there a way to add a template conditionally? – dave paola Aug 19 '10 at 0:13

Hooks are not pushed to server via git push. Otherwise, this would arise a severe security issue: anyone can push code that is executed on your server with higher privileges.

To workaround the issue, you may just copy the hook into the created directory, and run it manually after your first push:

GIT_DIR=. hooks/post-receive

You'll have to do this only once.

  • I'm trying to do this programatically though. These repositories are created by a script. – dave paola Aug 18 '10 at 6:25
  • @davezor, well, the most obiovus way then would be to fix gitosis itself, so it stores per-repository hooks inside gitosis repository, and saves them to the proper folders. I think such functionality (unless it's already implemented) would be useful to community as well. – P Shved Aug 18 '10 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.