Sharing GIT repositories with SSH for Mercurial users

I have used Mercurial for a lot of my private projects now and was always very satisfied with it. It’s a great source code management tool. I am working with different machines, so I need a shared repository to get access to the latest revisions everywhere. Since I have a virtual machine hosted at Linode, I setup a user named hg with SSH access. Now for every new project I created a directory inside the home directory of the hg user. Then I cloned the local project to the directory on my virtual machine. The cool thing with Mercurial is that you can clone in any direction not only from extern to local but also your local repository to an extern one. Just call hg clone . ssh://hg@hg.example.com/myproject to clone the current project to an SSH share. And from that point on I could easily push and pull to and from the SSH share.

Now since the whole developer world seems to move toward GIT I wanted to get some experience with it and use it for my next project. But I had some trouble to set up a shared repository with a SSH account. I had to do quite a bit of research to find the solution. So here I go:

On the server:

  • Create a directory for your project, i.e. myproj
  • cd into the this directory
  • Execute git –bare init

On the workstation:

  • Add the project to a local git repository of not already done
  • Execute git remote add origin git@git.example.com:myproj
  • Execute git push origin master
From now on you can fetch and merge changes from the server and push your changes to the server.

Leave a Reply

Your email address will not be published. Required fields are marked *