Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right way to share a git repo over ssh

Tags:

git

ssh

I'm using a box as a shared repo, and my team connects to it via ssh.

What I do is:

  1. Create an empty git repository on the central machine git init

  2. Then from each workstation do something like git clone ssh://user@central-box/Users/user/Projects/my-project/.git/

This works nice, but git keeps yelling at me every time I make a push something like this:

alt text

Is there a better way of sharing a repo over ssh.

IMPORTANT: I'm well aware of the existence of gitosis and tools like that, I do not want anything fancy. Just sharing a .git repo over ssh.

Thanks

like image 307
Pablo Fernandez Avatar asked Sep 07 '10 14:09

Pablo Fernandez


People also ask

How do I share a Git repository with others?

Under your repository name, click Settings. In the "Access" section of the sidebar, click Collaborators & teams. Click Invite a collaborator. In the search field, start typing the name of person you want to invite, then click a name in the list of matches.


2 Answers

On the host machine you should do

git init --bare

Because you don't need the actual files, just the repo.

If the warning message is on a FIRST push to a repo, and no one has touched it, do a

git push -f

Otherwise, this error means your branch scheme isn't correct. You should NOT be editing the branch origin/branchname. You want your own local branch called branchname, then when you are ready to check in your code you do

git commit
git pull
git push

And you will push from your local branchname to origin/branchname.

Edit

I would like to see the output of this command in your local repo:

git branch

You should not see the word origin or your server name anywhere in the output

like image 89
bwawok Avatar answered Sep 28 '22 08:09

bwawok


In addition to bwawok's solution, you'll need to watch out for permission issues. By default, when git creates files on a user's behalf, their permissions are sourced from the user's umask and their group is set to the user's default group. For common umasks and default groups, this will break a shared repo, since such files will be unmodifiable by other users.

Fortunately, git can be configured to do the right thing in this situation: Take a look at the --shared option to git init (or the core.sharedRepository setting). The simplest option is probably --shared=group, which grants write access to all users in the "git" group.

like image 41
dhaffey Avatar answered Sep 28 '22 08:09

dhaffey