Search code examples
gitrepositorysharedgit-bare

Git, How to change a bare to a shared repo?


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?


Solution

  • 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.