Redline Software Inc. - Winnipeg's Leader in Ruby on Rails Development

Converting Subversion Repositories to Git

Remote setup

I’m going to keep this post mostly about converting your SVN repository into a Git one. As far as setting up your remote server goes, we can get to that in another article. I basically stick with a simple setup. Create a Git user, set the shell to git-shell and use Git via SSH. You’ll likely want to play around with Git first before worrying about converting old SVN repositories into it.

Local setup

I create myself a file called gitauthors which is just a text file which maps SVN user names to Git user names. For example my gitauthors file looks like:

1
2
marc = Marc Jeanson <marc@redlinesoftware.com>
andrew = Andrew Kaspick <andrew@redlinesoftware.com>

In this example, “marc” and “andrew” were the SVN users and the email address style is the Git user names. We’ll be using this mapping when we convert the SVN repo into Git so that we can keep the history of who checked in what.

git-svnimport

Lets create the new local Git repository. In this example replace projname with your project’s name and replace https://your-repo-host.com/projname with your Subversion url (note this can take a while if your repo has lots of revisions):

1
git-svnimport -C projname -r -v -A authors https://your-repo-host.com/projname

Bare essentials

Now you’ll have a local Git repository called projname. For your “central” repository you won’t want to have a local checkout in that repo so I do the following:

1
git clone --bare projname projname.git

The projname.git will be the repository that you’ll want to upload to your remote server. The —bare option here creates a repository without a local checkout. You might want to look into the —shared option depending on how you setup your remote server and permissions. After uploading it you can nuke the projname.git repository on your local machine.

Hooking up the remote

Since your projname directory is still there and has a nice working version already in it, you can edit the .git/config file and append the following:

1
2
3
4
5
6
[remote "origin"]
  url = git@your-git-remote-server:/home/git/projname.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master

I’m assuming that your repository is in the /home/git directory on your server. You’ll want to change that to wherever you put your repositories.

But my git-svn and git-svnimport are busted!

You might experience some errors when using git-svn. Usually this is caused by not having the correct Perl bindings needed for the git-svn hookup. If you’re on a Mac and you installed Git using Macports, try doing this:

1
2
sudo port deactivate git-core
sudo port install git-core +svn

If you’re on another platform, try running cpan and installing the Perl libraries that you need. For example if you have an error like “Can’t locate Blah.pm in @INC” then you need to install the Blah Perl library.

Comments