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
Best Answer
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: