Fixing Git Object Permissionscomments
I’ve recently become more annoyed with permissions issues in a git repository that I have set up on my personal box. Every time someone commits changes, some files within
end up having the owner set to the user who made the commit, but that’s not what I want. The goal is to have a single
git user and group with permissions to all the files, and to add users who should have access to the repository to the
Today I decided to tackle this problem via git hooks.
Before we go on, I want to acknowledge the fact that I’m no git administration expert, and you should follow this approach at your own risk.
With that being set, here’s what I did to address the problem:
git user permissions to alter permissions:
You’ll need to add the following lines to your sudoers file in order for your
git user to be able to make the necessary permissions changes:
If you’ve never altered your sudoers file before, you can begin editing it with vim by entering
Note: We’re technically giving anyone in the
git group permissions to alter permissions on any file, but they can only set permission to the
git group. However with this in place, anyone in the git group can alter any files permissions to give themselves access to it! This isn’t a great idea, but admittedly I was struggling with restricting the permissions to my
git user’s home directory, so I left it here.
Update permissions from git hooks
Use the following script to alter an already-created git repository, adding hook logic to update the permissions.
Once you’ve created the script and given it execute permissions via
you’re ready to run it. Execute the script using a command like
After that, committing to the repository should now fire off the
chown commands that we’ve applied using our script, effectively resetting all permissions back to our