Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep git from changing file ownership

I have been noticing that when I pull from my github repo on a development server(Red Hat) the ownership of the files change after the pull is completed. The .git file used to be owned by me but then I noticed that it would write files as me and I need it to write files as a different user. So i changed the ownership of the .git directory.

I stumbled on to git config core.filemode which was true. I since have set to it false. I have not seen a difference after setting this to false. What should I do to keep my files ownership from changing.

This doesn't happen to me locally.

like image 818
user2108258 Avatar asked Feb 25 '13 20:02

user2108258


People also ask

Does Git save file ownership?

Git Tracks ONLY the Executable Bit of the Permissions for the User Who Owns the File.

Does GIT care about file permissions?

By default, git will update execute file permissions if you change them. It will not change or track any other permissions. If you don't see any changes when modifying execute permission, you probably have a configuration in git which ignore file mode.

How do I restrict a file in Git?

You can't. If you give someone the push permission, he will be able to push whatever he want. If you want someone to have a partial access, you have many choices: Make him fork and pull-request the repository.

How do I change permissions in git?

Open Security for a repositoryOpen Project settings>Repositories. To set the permissions for all Git repositories, choose Security.


1 Answers

If it suffices to preserve the group, you can set the setgid flag on the directories. See http://en.wikipedia.org/wiki/Setuid

Setting the setgid permission on a directory ("chmod g+s") causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner ID is never affected, only the group ID). Newly created subdirectories inherit the setgid bit. Thus, this enables a shared workspace for a group without the inconvenience of requiring group members to explicitly change their current group before creating new files or directories. Note that setting the setgid permission on a directory only affects the group ID of new files and subdirectories created after the setgid bit is set, and is not applied to existing entities. Setting the setgid bit on existing subdirectories must be done manually, with a command such as the following:

[root@foo]# find /path/to/directory -type d -exec chmod g+s '{}' \;

like image 83
nafg Avatar answered Oct 22 '22 10:10

nafg