skip down to the 3 comments

Setting up your own hosted private Git repository

Now I’m a fully paid up user of Github. It’s a wonderful service, site and community of developers. But for the account plan I can afford, I only get 5 private repositories. I’m happy to make my work public, but there are some bits of software I want to keep private right now and yet still have remote copies of, and this comes to more that 5. I still want to use Git, and maybe one day make them public on Github. Here’s my solution using my own hosting as a private Git repository and just using Git and SSH to do the job.

Before we start, I’m assuming that you have SSH access to your hosting, and you have Git installed both on your machine and on the host.

First create a folder on your remote machine to hold the repos

$ ssh
$ mkdir git
$ exit

If you have the correct permission or sudo access you could do the same as me and create the dir at /opt/git. You’ll need to replace all other mentions of git with this new path if you go this route.

Navigate to the local git repos on your machine that you want to have a remote copy of. Running the command below will give you a bare copy of the repos in your tmp dir.

$ git clone --bare /path/to/myrepo/.git /tmp/myrepo.git

Now you need to get this copy onto your remote machine. There are various ways but the simplest is scp with the recursive flag set:

$ scp -r /tmp/myrepo.git

You have a couple of choices now. You can either just navigate in into your local git repos and add your remote git as a remote to your config like this:

$ git remote add myserver

or you can delete your old repos and check out the remote one. Make sure you backup the old one until you’re sure it works ok though.

$ git clone

You can now make changes and push them to your new remote repos when ever you want.

Hope this helps someone. It doesn’t solve everything, but is a simple way to have a private alternate copy of your Git repositories.

There have been 3 responses to this post.

  1. Mo

    Orrrr, instead of the clone and scp, which is a little kludgy, just do (on the server)…

    mkdir git/myrepo.git
    cd git/myrepo.git
    git init –bare

    Then, once you’ve added the remote on the client, just push to it and it’ll populate the repro for you.

    (Indeed, you could always stick the preceding commands in a script which executed them via SSH if you wanted…)

  2. Duncan

    @mo ta!

  3. Aleksy V Zapparov AKA ixti

    If you have SU right on your server, IMHO it’s easier and more comfortable to deploy gitolite or gitosis (deployment takes two commands more in comparison to your variant in fact ;) )

    But even if you are not – you still can use these two awesome apps. All you need is SSH, GIT and PERL ;) )

back to the top