I've spent the past few days trying to set up a Git Remote on my server so I can push changes to my web-server to it. The problem is that I'm getting the following errors while doing it:

$ git push --porcelain --progress --recurse-submodules=check live refs/heads/master:refs/heads/master
'master' pushed: d689cce..4e755fc
Delta compression using up to 4 threads.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: unable to create file .gitignore (Permission denied)        
remote: error: unable to create file .gitignore~ (Permission denied)        
remote: error: unable to create file index.js (Permission denied)        
remote: error: unable to create file package.json (Permission denied)   

Now, I get that this has something to do with file and folder ownership, and that I and/or git may or may not have write access to certain folders.

Trouble is I don't have the faintest clue which folder I can't write to or how to resolve it.

I'm brand new to messing with setting up a web-server from scratch, so here's what I did:

I went through How To Set Up Automatic Deployment with Git with a VPS to try and see how I should get the remote up and running. This lead me to create the following two folders: /var/repo/site.git and /var/www/website.

Without being told anything about permissions I went ahead and tried to push to the remote as told, immediately running into the first permission roadblock.

So I consulted a friend who suggested I should make a new group, add my user to the group, and then have /var/repo be owned by said group with the 775 read/write/execute permissions. He also suggested I should do as suggested here to make sure the /var/www folder had the right permissions; but even after all that I still can't push to the remote as shown in the error above.

So what am I supposed to do to fix this? I'm kinda at a roadblock here.

Some info about the stuff I use:

  • Client OS: OSX Yosemite
  • Server OS: Ubuntu 15.04
  • Git Client: SmartGit 6.5 (for convenience)
  • I use SSH rather than HTTPS to connect to the remote
  • Does each user have their own system user account, where they push to ssh://username@gitserver? Or is there just a single git@gitserver account with keys for different users? – Will Jul 13 '15 at 19:02
  • @Will there's root@server, user@server, but I don't know if there's a git@server – Electric Coffee Jul 13 '15 at 19:04

The issue is not write access on /var/repo - I believe from the errors you've copied/pasted that this is set up correctly and probably always was.

The issue is a lack of write permissions on /var/www.

By following the instructions you've linked to what you've set up is a script that automatically takes the files you push to the git repository on the server and publishes them in /var/www. This is a smart approach in my opinion, but that script (which lives in the file /var/repo/hooks/post-receive) is being run as the same that pushes to the git repository. That user doesn't appear to have permission to write to /var/www

Assuming you've already followed the steps from the previous answer, these two additional commands should put things right:

chown -R root:git-users /var/www/

chmod -R g+rw /var/www/    
  • I figured I could just have the user be a member of two different groups and still have it work.. but I guess not. This worked – Electric Coffee Jul 13 '15 at 20:36
  • Good catch! I was thinking this was on the git-repo side :) – Will Jul 13 '15 at 20:47

Since you've said in the comments that users push to git via their username@server, you need to make sure all git users have read and write permissions to the repository.

Add all users to a common group, called, say, git-users.

groupadd git-users

Now add each git user to the group:

usermod -a -G git-users <username>

Now, change the ownership group for the git repository:

chown -R root:git-users /var/repo/

Now, set permissions such that the group can read and write to the repo:

chmod -R g+rw /var/repo/

Now, any member of the group git-users has read and write access.

Now we need the setgid bit for directories only:

 find /var/repo/ -type d -exec chmod g+s {} \;

Additionally, you need to enable the sharedRepository setting in the remote git configuration:

sharedRepository = true
  • Didn't change a thing. What you said is essentially the same as what my friend told me, and even doing everything you said step by step I still get the same errors – Electric Coffee Jul 13 '15 at 19:47
  • Try what I just added in my edit. It does seem that there's more to it. If this still doesn't work, report back :) – Will Jul 13 '15 at 19:55
  • Same error, I added that line to the config file I found in site.git.. not working – Electric Coffee Jul 13 '15 at 20:03
  • Did you do the g+s part? So if that's still not working, try sharedRepository = group rather than sharedRepository = true. – Will Jul 13 '15 at 20:05
  • do I need to re-init the git folder or something, cuz it's still not working – Electric Coffee Jul 13 '15 at 20:14

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.