Every time I do git pull
or git reset
, git
resets changes to permissions and ownership I made. See for yourself:
#!/usr/bin/env bash
rm -rf 1 2
mkdir 1
cd 1
git init
echo 1 > 1 && git add 1 && git ci -m 1
git clone . ../2
cd $_
chmod 0640 1
chgrp http 1
cd ../1
echo 12 > 1 && git ci -am 2
cd ../2
stat 1
git pull
stat 1
The output:
$ ./1.sh 2>/dev/null | grep -F 'Access: ('
Access: (0640/-rw-r-----) Uid: ( 1000/ yuri) Gid: ( 33/ http)
Access: (0664/-rw-rw-r--) Uid: ( 1000/ yuri) Gid: ( 1000/ yuri)
Is there a way to work around it?
I want to make some files/directories accessible for writing by the web server.
Best Answer
This sounds like the user you're running has the default group set to
yuri
. You can confirm this like so:The UID of your account is this:
uid=1000(saml)
whereas the default group isgit=1000(saml)
and any secondary groups are thereafter.NOTE: If you want the git clone to have specific ownership, then you have at least 2 options.
Option #1
Set a parent directory with the permissions as you want like so:
This forced the directory
topdir
to enforce any child directories underneath it to have the grouphttp
applied. This will work by in large but can lead to problems, since if you move files into this git clone workspace, those files will not have their groups enforced by the changes made above.Option #2
Prior to doing work, change your default group to
http
like so:This method will force any new files created to have their group set to
http
instead of your normal default group ofyuri
, but this will only work so long as you remember to do anewgrp
prior to working in this workspace.Other options
If neither of these seem acceptable you can try using ACLs instead on the git workspace directory. These are discussed in multiple Q&A's on this site, such as in this Q&A titled: Getting new files to inherit group permissions on Linux.