1

Recently I came across permission related issue for a file in git. Actually one of my team members while committing a file didn't notice there is no write permission for group level.

Consider a file - file.txt. She committed and pushed the file, while the permission on her machine was - 644 (rw-r--r--). And when I tried to do a git pull, it returned with following error for that file:

$ git pull error: unable to create file file.txt 

So I did try a couple of things without success:

  • First I changed the file permission on my team member machine, and pushed it again. But that didn't help.
  • Then I deleted the file, and re-created it with proper permission. And then added the new file to git. Again, that didn't work.

Finally I've to resort to use sudo:

$ sudo git pull 

And that did work. But I'm still unknown about how to fix the issue without using sudo?

1 Answer 1

1

644 and 755 are the only tow permissions recorded by Git.

sudo should not be used usually, unless you are in a common server (accessed by multiple users) where the local repo is not created as you.

If it is your repo, try a:

sudo chown -R <yourUser> . 

And see if the error persist on git pull.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm trying the re-produce the issue on my machine, creating a local and remote repo. I pushed a file with owner as root and 644 as permission, and pulled that on a different local repo. Suprisingly it created the file.. :( And it changed the owner to me, and permission to 664.
@RohitJain that is expected. 644 is a perfectly fine permission. The repo is a local rpeo and operation will be done as the local user which operates said local repo.
So, if I would have changed the owner of that file from my team member's machine to her user, instead of root, it would work?
@RohitJain yes, using root is generally not a good practice for a local repo owned by a user.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.