Permissions Problems with git pull

I’ve started working on Doc5 from a laptop in the last few months and have begun the pull/push process to get my Bitbucket repo and desktop machine all in sync. But when trying to get these sorted I found permissions problems on one of the local repos. When I tried to do a pull I had about eight files that either couldn’t be unlinked or couldn’t be created.

If I looked at the permissions on the files I was the owner, www-data (Apache in Ubuntu) was the group and the permissions where 644 on the files and 755 on the directories in my project folder. So that all seemed fine.

But what you need to watch for is the extra permissions that a process needs in order to unlink. What git is doing is taking these files away and then replacing them in the folder. i.e. it’s not just a modification through a write action to the file.

If you look at all the files in the directory and their permissions by using

ls -la

you will also see the top two entries for “.” and “..” and you may see that “.” (the object that represents the directory you’re in), does not reflect the permissions you’ve set on everything else. Well why would it? It represents where you are not something inside where you are.

So the solution* is to move up to the parent directory and chmod (or chown) as needed on the directory you’re trying to do the git pull into. If you drop back into the directory and have another look at “.” it should now be owned by you, or at least give you write and execute permissions. Directories need to have execute permissions to allow you to unlink files.

Run your git pull and you should see the permissions problem is now resolved. Of course I then battled with git merges but that’s another issue.

* There are other reasons for the permissions issues, a number of which to be caused by other processes holding files open. So make sure your IDE and any other tools aren’t the culprit either.

Leave a Reply

Your email address will not be published. Required fields are marked *