I have an existing git repo (a bare one) which has up to this point only been writable by me. I want to open it up to some UNIX user group, foo, so that all members of foo can push to it. I'm aware that I can easily set up a new git repo with:
git init --bare --shared=group repodir chgrp -R foo repodir
But I need the equivalent operation for an existing repo dir.
Specify that the Git repository is to be shared amongst several users. This allows users belonging to the same group to push into that repository. When specified, the config variable "core. sharedRepository" is set so that files and directories under $GIT_DIR are created with the requested permissions.
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.
Try this to make an existing repository in repodir
work for users in group foo
:
chgrp -R foo repodir # set the group chmod -R g+rw repodir # allow the group to read/write chmod g+s `find repodir -type d` # new files get group id of directory git init --bare --shared=all repodir # sets some important variables in repodir/config ("core.sharedRepository=2" and "receive.denyNonFastforwards=true")
Merging @David Underhill and @kixorz answers, I made my own (definitive) solution.
It is for bare repos and non-bare repos. There are only little differences between them, but in this way is clearer.
BARE REPOSITORY
cd <repo.git>/ # Enter inside the git repo git config core.sharedRepository group # Update the git's config chgrp -R <group-name> . # Change files and directories' group chmod -R g+w . # Change permissions chmod g-w objects/pack/* # Git pack files should be immutable find -type d -exec chmod g+s {} + # New files get directory's group id
where:
<repo.git>
is the bare repository directory, typically on the server (e.g. my_project.git/
).<group-name>
is the group name for git users (e.g. users).NON-BARE REPOSITORY
cd <project_dir>/ # Enter inside the project directory git config core.sharedRepository group # Update the git's config chgrp -R <group-name> . # Change files and directories' group chmod -R g+w . # Change permissions chmod g-w .git/objects/pack/* # Git pack files should be immutable find -type d -exec chmod g+s {} + # New files get directory's group id
where:
<project_dir>
is the project directory containing the .git
folder.<group-name>
is the group name for git users (e.g. users).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With