19

Git allows to create a shared repository amongs a group:

git --bare init --shared=group

However - how can I change already existing repository to shared? I don't want to re-git-init it.

Vojtěch
  • 11,312
  • 31
  • 103
  • 173
  • 2
    Is this what you are looking for? http://stackoverflow.com/questions/3242282/how-to-configure-an-existing-git-repo-to-be-shared-by-a-unix-group – Luwe Sep 01 '11 at 09:44
  • Possible duplicate of http://stackoverflow.com/questions/3242282/how-to-configure-an-existing-git-repo-to-be-shared-by-a-unix-group/3242364#3242364 – Mark Longair Sep 01 '11 at 09:45
  • 2
    Possible duplicate of [How to configure an existing git repo to be shared by a UNIX group](https://stackoverflow.com/questions/3242282/how-to-configure-an-existing-git-repo-to-be-shared-by-a-unix-group) – Pod Aug 21 '17 at 09:12

2 Answers2

21

According to the documentation:

--shared[=(false|true|umask|group|all|world|everybody|0xxx)]

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. When not specified, git will use permissions reported by umask(2).

Therefore, in order to change the permission, chmod everything to your liking, and set the core.sharedRepository in git config accordingly:

git config core.sharedRepository true
akxlr
  • 1,142
  • 9
  • 23
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
11

To make a private bare repo group shared:

  1. Edit config and add sharedRepository = group to the core section
  2. Fix permissions from inside the repo:
    • chgrp -R target-group .
    • find . -type d | xargs chmod g+ws
    • find refs -type f | xargs chmod g+w
Jan Wielemaker
  • 1,670
  • 10
  • 18
  • Very bad answer.... `sharedRepository = mygroup` returns `remote: fatal: bad numeric config value 'mygroup' for 'core.sharedrepository': invalid unit` and none of those `chmod`s are fixing permissions. – Alex G Aug 02 '16 at 23:06
  • 5
    It says `sharedRepository = group`, *not* `sharedRepository = mygroup`, i.e., this is not the group you are using, but always `group`. The group you are using is `target group` in the example. These commands surely work on any Unix-like OS if you run them with sufficient privileges. – Jan Wielemaker Aug 04 '16 at 07:19
  • Doing `--shared` seems to also add this to my config: `[receive] denyNonFastforwards = true`. I'm assuming it is a good idea to also add this manually when converting an existing repository to shared. – Harry Pehkonen Oct 03 '16 at 18:39