Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What file permissions should the contents of $GIT_DIR have?

Tags:

git

I have restored a git repo from backup and it does not have the correct file permissions. Is it enough to set owner +rw on all files and directories in .git, or is it more subtle?

Is there a utility to check or reset .git file permissions?

like image 904
Alec the Geek Avatar asked Sep 06 '10 02:09

Alec the Geek


People also ask

What is 644 permission Linux?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access.

What is the usual permission setting for a file and a directory?

There are three permission types: read, write, and execute. Read: The capability to read contents. This is expressed as either the number 4 or letter r. Write: The capability to write or modify.

Does Git preserve directory permissions?

1 Answer. Show activity on this post. When Git checks out files, it by default uses the umask of the file on the system, setting the executable bit if it's a directory or it's marked as an executable file. That's because Git removes and re-creates the file, so it doesn't preserve the permissions of the existing file.


1 Answers

Directories should have 755 permission; files should have 644 permission.

That's a pretty good rule of thumb unless you expect members of your group to make changes to your repository.

Having said that, in one of my repositories, the files under .git/objects/* have 444 (readonly) permission for everyone. Other files are 644 as suggested.

This script, run in the top-level directory just above the .git repository would fix the permissions:

 find .git -type d | xargs chmod 755
 find .git/objects -type f | xargs chmod 444
 find .git -type f | grep -v /objects/ | xargs chmod 644

I started with -print0 for the first two find commands and xargs -0 to allow for the remote possibility of spaces in file names. But the grep -v in the third command would be difficult to manage with the -print0 format - so I omitted the space-safe notation from all the commands, knowing that git does not create files with spacing in names under the .git directory.

like image 148
Jonathan Leffler Avatar answered Sep 28 '22 10:09

Jonathan Leffler