I use root
to run git,the files permission mode changed to root 644
each time when I checkout, which means apache
cannot delete,modify.
Then I decide to make GIT to checkout files with permission 777
. I know set umask 000(default is 022
) can do that, but I don't want to change my centos setting.
How to do it?

- 2,255
- 5
- 24
- 52
-
3Setting files to mode 777 is almost never a good idea since it defeats *any* security. See [this question and its answers](https://stackoverflow.com/q/3242282/421705) for better (i.e. better integrated and more secure) ways to set the permissions. Also, have a look at the [documentation](https://git-scm.com/docs/git-init#git-init---sharedfalsetrueumaskgroupallworldeverybody0xxx) for details and more options. – Holger Just Jun 18 '17 at 15:21
-
2To mode 777 is for avoid any permission problem. It's my develop pc, not production server. – kittygirl Jun 18 '17 at 15:35
-
You're trying to use Git as a deployment tool. Git is a bad deployment tool. Instead, a proper install/deployment tool would handle building and installing and setting permissions. You'd do all of that as a normal user, only requiring you to use `sudo` to do the install. Its a bad habit to do anything root. – Schwern Jun 18 '17 at 17:41
3 Answers
With Git 2.9 or more, you can do
git add --chmod=+x -- afile
git commit -m "Executable!"
Then, on the next clone or checkout, the file will be executable.
Sidenote: a proper umask
would be 022 (for 755) or 002 for 775. 777 is generally not recommended.
Note 777 (even with git update-index
) does not make sense, as Git itself does not record write: only 644
or 755
, spelled 100644
and 100755
, with the 100
part meaning "regular file".

- 1,262,500
- 529
- 4,410
- 5,250
git config core.sharedRepository 0664
. See git help config.
PS. I use mode 664 because it's more secure than wide-open 666. Git adds executable bit (thus making the mode 775 or 777) for directories automatically.

- 82,685
- 13
- 120
- 165
-
`664` means apache cannot delete file in this folder. Based on VonC answer, `666` is not allowed in git. – kittygirl Jun 18 '17 at 15:42
-
1Then `chown -R apache.apache` (or www-data.www.data) and always do `su - apache` to work with that repo. That way you guarantee Apache will always has r/w access. – phd Jun 18 '17 at 16:31
find . -type f -not -name '.git*' | xargs chmod 777
find . -type d -not -name '.git*' | xargs chmod 666
I use this in post-checkout hooks and seemed without any problem till now.

- 2,255
- 5
- 24
- 52