Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push error: Unable to unlink old (Permission denied)

In the remote server I have a post-receive hook set up in order to make a git checkout of my repository:

#!/bin/sh
GIT_WORK_TREE=/var/www/<website> git checkout -f

But when I make a push from my local machine to the git repository in the server, I get the following error messages:

remote: error: unable to unlink old '<file>' (Permission denied)

This appears many times over, one error message for almost every file.

However I have a README.txt file that I'm able to change using git, here are its permissions:

-rw-r--r--  1 <serverusername>  <serverusername>  2939 Aug  2 10:58 README.txt

But other files with exactly the same owner and same permissions, give me that error.

In another local repository for another website, I have the files with my local machine username as owner, and when I push to the remote server it respects the remote server owner of the files and works like a charm.

Obviously it seems a permissions related error, but I can't find a way to fix it, any suggestions?

like image 388
rfc1484 Avatar asked Aug 02 '12 09:08

rfc1484


4 Answers

When you have to unlink file, you have to have permission 'w' for directory, in which file is, not for the file...

like image 112
Jan Marek Avatar answered Oct 08 '22 19:10

Jan Marek


sudo chmod -R ug+w .;

This command would fix the issue. It gives write permissions to the folder.

like image 22
Rajendra kumar Vankadari Avatar answered Oct 08 '22 19:10

Rajendra kumar Vankadari


If you are using any IDE most likely the problem is that file was used by some process. Like your tomcat might be using the file. Try to identify that particular process and close it. That should solve your problem.

like image 49
Krishna Gollapudi Avatar answered Oct 08 '22 20:10

Krishna Gollapudi


I think the problem may be with the ownership to the folder so set it to the current user ownership

sudo chown -R your_login_name /path/to/folder
You can find the solution [here][1]
like image 32
Soumitra Sarkar Avatar answered Oct 08 '22 19:10

Soumitra Sarkar