32

So this is how I set up my project:

git init --bare

Later I learned that if you want to work on a project with multiple users this is how I should have done it:

git init --bare --shared

Now I tried to work like that and luckily we are in the beginning so I could set up git again. I still wonder though when you're in the middle of a project you can't do that. Is there a way that i can change a bare repo to a shared one?

bottleboot
  • 1,631
  • 2
  • 24
  • 39
  • 1
    Another use case where one would want to modify an existing bare repo is if your remote repo got corrupted and you're trying to replace it with a bare repo you reverse-engineered from a regular repo. – Sridhar Sarnobat Jan 15 '16 at 23:22
  • 2
    As early as `git 1.7.1` you can just run the `git init --bare --shared` command in an *exiting* bare repo and `git` will *reinitialize* the repo with the specified sharing. – go2null Jun 04 '16 at 00:26
  • Possible duplicate of [How to configure an existing git repo to be shared by a UNIX group](http://stackoverflow.com/questions/3242282/how-to-configure-an-existing-git-repo-to-be-shared-by-a-unix-group) – Trevor Boyd Smith Sep 08 '16 at 14:44

4 Answers4

40

Since the --shared option just sets the permissions on everything in the repository to group-writable you could do this manually later:

$ chmod -R g+w the/repo/path

Plus, add

sharedrepository = 1

under the [core] section in .git/config. Shared repos also have the following receive option defined by default (which you may or may not want):

[receive]
    denyNonFastforwards = true

Note: In order to decide whether you want denyNonFastforwards: This option means a merge never happens in the shared repository, which, in turn, means there is never a merge conflict on the shared repository. Instead the push is rejected forcing the user to do the merge in their local repository where it's much easier to fix and where it doesn't interfere with other people's use of the shared repo.

Dale Wilson
  • 8,374
  • 2
  • 27
  • 47
miku
  • 161,705
  • 45
  • 286
  • 300
  • Aha ok! Good to know, wish I had asked this before. Thanks! – bottleboot Jan 16 '12 at 16:46
  • 1
    Ok, I see! I just read the @jørgensen answer which confirms that. Stackoverflow should have a combined answer button :D! Thank you all a lot that was very enlightening! – bottleboot Jan 16 '12 at 16:53
  • Didn't work for me. It required `chmod -R g+s ...`. A fresh `git init --bare --shared` will have the group rights "rws". (Ubuntu 12.04) – Unapiedra Jan 29 '14 at 15:11
  • @Unapiedra - You want to add the group sticky-bit on all the directories but the regular files should just be g+rw . The sticky-bit will ensure any new files will have the same group setting. – Tim Tisdall Jan 20 '15 at 15:19
  • FYI: In many references it is also suggested to use `sharedrepository = group`, according to the man page this is the same as `sharedrepository = 1`! – lanoxx Apr 15 '15 at 11:24
5

Probably if you try to share an existent repository, you may have lots of different users commits.

1.If you have super user permission, you can go forward and change all permissions by yourself using the step two, in any-other case you will need to ask all users with objects created with their users, use the following command to know who they are:

$ ls -la | awk '{print $3}' | sort -u 
<your user_name>
<his user_name>

2.Now you and all file's owner users will have to change those files permission, doing:

$ chmod -R 774 .

3.After that you will need to add a new property that is equivalent to --shared=group done for the new repository, according to the documentation, this make the repository group-writable, do it executing:

$ git config core.sharedRepository group
helmedeiros
  • 447
  • 6
  • 4
5

Besides chmod -R g+w, you also need to edit (.git/)config and set core.sharedRepository = .... For ..., there are a handful of values, described in git-init(1).

jørgensen
  • 9,470
  • 2
  • 18
  • 26
3

If you're trying to share the repository off of the the host it is on, there are additional configuration steps you have to make (ssh stuff).

http://shapeshed.com/setting_up_git_for_multiple_developers/

http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/