Question

Git auto-deploy from Webhook giving permissions error?

Hi all. I have an Ubuntu server which I want to update whenever new code is pushed to a remote repository. I can successfully run a “git pull” from the command line when I Putty into the server and am at the file location. I have code working to verify the secret key is correct, but I can’t seem to get the code to execute “git pull” successfully. It returns the following error: “error: cannot open .git/FETCH_HEAD: Permission denied”

This makes me think that the “user” (the script being run) doesn’t have permission to access git? Because I can manually run “git pull” from the directory in Putty successfully, but when using PHP and putting shell_exec(‘git pull’), it returns that error.

I assume the solution needs to involve setting user permissions in the line before calling git pull. But I’m unsure what this shell snippet code should be.

Thanks every much for your help, I’m brand new to Digital ocean, and cloud computing in general.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey friend,

It sounds like you’re running as a privileged user (not root) and executing a git pull on files that the user does not have access to. You could probably just make the user a sudo user and toss a sudo in front of the git pull. There are other ways to do it but it depends on your user/group setup.

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Jarland