Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure an existing git repo to be shared by a UNIX group

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.

like image 586
Pistos Avatar asked Jul 13 '10 23:07

Pistos


People also ask

How do I initialize a git repository in shared mode?

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.

Which command is used to create a shared repository in git?

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.


2 Answers

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") 
like image 118
David Underhill Avatar answered Sep 20 '22 14:09

David Underhill


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).
like image 37
Andrea Avatar answered Sep 17 '22 14:09

Andrea