danlucraft /blog

Migrating from Subversion to git

November 2007 • Daniel Lucraft

You have a public svn repository served by svnserve on your server. You would like to migrate to a public git server. Here’s how.

Importing your svn repository

First we have to get your subversion repository into git. Let’s say your repository is in /home/dbl/svn/rak (this is totally made up - obviously). I would like to create a git repository in /home/dbl/git/rak.

$ cd /home/dbl/git
$ git-svnimport -v -C rak1 file:///home/dbl/svn/rak

This will initialize the git repository and import the svn history. The -v simply means I can watch the progress. -C rak1 is the directory the repository will be in - note that I put it into rak1 rather than rak. This is because we are now going to move it.

The git-svnimport command checks out a working copy into the “rak1” directory. If you use the server as a working area and not just a server, that’s ok, but I just want to use it as a server so I have to get rid of the working copy. We do this by creating a ‘bare’ repository:

/home/dbl/git $ git clone --bare rak1 rak

If you look into rak/ now, you will see the contents of rak1/.git/. This is now a repository without a working copy, which is exactly what we want on a server.

Using git-daemon

You can remotely clone and use this repository right away with ssh, but I like to change my ssh port for security and that’s no good if you want your repository to be public. So let’s start git-daemon. The git-daemon listens on 9418, so you’ll need to make sure that is open. There are lots of options for this, but this works for me:

git-daemon --base-path=/home/dbl/git

You should probably add this to your cron to start on reboot. To get it working right away I actually typed:

nohup git-daemon --base-path=/home/dbl/git &

Now we have to tell the daemon which repos it’s ok to serve. git-daemon checks to see if the git-daemon-export-ok file exists, so:

touch /home/dbl/git/rak/git-daemon-export-ok

You can now clone your repository from your local machine with:

git clone git://www.yourserver.com/rak

The git-daemon doesn’t support push, so to push your changes back up to the server you’ll have to use ssh as in the git User Manual.

Setting up gitweb

If you would like a fancy repository browser like git.donttreadonme.co.uk, you could do worse than checking these instructions.

And that’s it!

blog comments powered by Disqus