Migrating SVN Repositories to Git

I’ve recently had to migrate a few SVN repositories to Git (can you believe there are people out there still using SVN in 2014?). This is a quick guide that walks you through all the steps you’ll need to migrate your repositories including all the history, branches and tags.

The steps below will perform a one-way migration, which is what you want to do when moving permanently off SVN to use Git. There are ways to keep both the SVN and Git repositories synchronized with each other, which I won’t be discussing here.

This short guide is based on Atlassian’s excellent 6-page guide, which you should refer to if you want a more in-depth explanation.

I’ve performed the migration using Git version 1.9.3 (Apple Git) and SVN version 1.7.17. Commands may vary slightly with different versions.

1. Download Tools

The migration can mostly be performed using the Git’s build-in tools, but for convenience, Atlassian has created a set of tools that would make the migration easier.

Download Atlassian migration tools from their BitBucket repository.

2. Mount a Case-Sensitive Disk Image

Skip this steps if you are not doing the migration on OS X.

Migration needs to be performed on a case-sensitive file system. Since OS X isn’t case-sensitive, we will need to mount a case-sensitive disk image to use for the migration.

$ java -jar ~/svn-migration-scripts.jar create-disk-image 5 GitMigration

$ cd ~/GitMigration

This will create a 5 GB disk image called GitMigration.

3. Create Authors File

Next, we need to extract all the usernames that made commits to the SVN repository and convert them to Git’s format of a full name and an email address.

$ java -jar ~/svn-migration-scripts.jar authors http://svnserver/path/to/repository > authors.txt

Open the newly created authors.txt file and modify the generated placeholder names and email addresses to match their actual values.

4. Clone Repository

This will do a svn checkout and convert the repository locally to a Git repository. We are also passing in the authors file we’ve just created to use while converting the repository commits history.

This assumes that your SVN repository uses the standard layout of trunk, branches and tags.

$ git svn clone --stdlayout --authors-file=authors.txt http://svnserver/path/to/repository <git-repo-name>

$ cd ~/GitMigration/<git-repo-name>

5. Clean Repository, Branches and Tags

This will convert SVN branches and tags into standard Git branches and tags.

$ java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git --force

6. Add Remote and Push

Add a new remote to the local Git repository.

$ git remote add origin https://username@github.com/team/<git-repo-name>.git

Now push all branches to the newly added remote.

$ git push -u origin --all

And finally, push all tags.

$ git push --tags

Your repository has now been completely migrated to Git. The final step is to forget SVN ever existed and enjoy using Git.