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?
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?
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.