Following the instructions in A web-focused Git workflow I set up a prime and hub repository on my web server and then cloned the hub to my machine at home.

I started testing commits and pushes with changed files in documentroot and the changes would appear fine on the root of the webserver. However, when I tried to push a file in a subdirectory, I rec'd the following message:

remote: **** Pulling changes into Prime [Hub's post-update hook]
remote: From /home/git/site_hub
remote:  * branch            master     -> FETCH_HEAD
remote: error: unable to create file academy/testthegit2.html (Permission denied)

Again, no permission issues in the web root, but put a file in a subdir and an error is tossed.

The git user is in the apache group and the sub-directories are chmod 755.

Here is the hub's post-update:


echo "**** Pulling changes into Prime [Hub's post-update hook]"

cd /usr/local/apache/htdocs || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info

and the prime (document root's) post-update:


echo "**** pushing changes to Hub [Prime's post-commit hook]"

git push hub

To reiterate, works in root, fails in subdir.

Thanks for any advice.


You need to add a wrapper to correct permissions on your post-update hook. Depending on how is your server setup, involves different steps. I'll describe my use case and hopefully you can adapt it to your needs.

In my server, the bare repositories (hub ones) are managed by gitosis/gitolite/plain git user with git-shell. Files under $GITOSIS_HOME are owned by gitosis:gitosis and are umasked 077.

For the changes to be pulled correctly, I needed to add a call to a helper script I'm storing in /usr/local/bin that recursively sets owner, group, permissions and SELinux context in the prime/live repository.

Incidentally, I also needed to add a line to my sudoers(5) file to allow gitosis to run the script as root with !requiretty and NOPASSWD.

  • Thanks. Would it be as simple as adding the git user to sudoers and allowing it to run git pull hub master as apache? I guess I'm unclear on the workflow of changing the web root permissions if it can't create the file there. – Ian Apr 12 '13 at 23:44
  • Added git ALL=(apache) NOPASSWD: /usr/bin/git to sudoers. rec'd the following when I tried to push from my laptop. remote: sudo: no tty present and no askpass program specified To ssh://git@example.com/~/site_hub – Ian Apr 13 '13 at 1:01
  • in case it helps, the laptop I'm pushing from is running msysGit as the client. – Ian Apr 13 '13 at 3:43
  • You are still missing to override the Default requiretty for the git user Default:git !requiretty – dawud Apr 13 '13 at 8:37
  • No, it's there. These are the last two lines in my sudoer: Defaults:git !requiretty, git ALL=(apache) NOPASSWD: /usr/bin/git but it still doesn't work. (Just to clarify my sudoer file says Defaults, not Default.) – Ian Apr 13 '13 at 19:55

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.