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?

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525

1 Answers1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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. – Rohit Jain Mar 08 '15 at 09:38
  • @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. – VonC Mar 08 '15 at 09:40
  • 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? – Rohit Jain Mar 08 '15 at 09:51
  • @RohitJain yes, using root is generally not a good practice for a local repo owned by a user. – VonC Mar 08 '15 at 09:56