Importing Subversion Repositories to Git

by Peter Jones / August 7, 2008

The following sections detail how to get different types of Subversion repositories loaded into Git.

Several Projects in a Single Repository

If your Subversion repository contains several projects, each of them having their own trunk, tags, and branches directories, the following commands will help you import them into Git.

Using the commands below, I imported a project called "devalot" from a local Subversion repository (created from a backup).

$ git-svn clone           \
  -T devalot/trunk        \
  -t devalot/tags/rel     \
  -b devalot/branches/exp \
  file:///some/path/to/repo devalot.git

You may also want to use the -A flag to git-svn. See the documentation for more information.

After the import is done, you probably want the master branch to point to the latest SVN trunk (I'm not sure why this isn't the default):

$ git checkout master
$ git reset --hard remotes/trunk

Also, the git-svn tool will leave all of your Subversion branches and tags as remote branches in your Git repository. You'll want to check them out and create local branches from them to preserve them after a clone.

When you are all done with the conversion, don't forget to repack your Git repository. It can greatly reduce the size of the newly converted repository.

Conversion Script and SVA

I wrote a script and some notes that will help you with the above steps. It was written to convert projects managed by my Subversion Automation tool (SVA), but can easily be hacked to work with any Subversion repository.


Tags: git svn git-svn