Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
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.

share|improve this answer
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. – Pavel Shved Aug 18 '10 at 6:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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