How to: Migrate your SVN repository to Git

You've probably heard a lot about how awesome Git is from all the cool people who are already using it. If you want to be part of the trendy crowd but feel tied down by your old Subversion repositories have no fear; Migrating all of those SVN repos to Git could not be easier and you get to keep the entire commit history of your project.

The first step is to create a text file that lists all of the users that would appear in your SVN repository and shows what their names would be for Git. The format is 'svn-username = Real Name <email address>', like so:

nathan-hoad = Nathan Hoad <[email protected]>
john-smith = John Smith <[email protected]>
jane-doe = Jane Doe <[email protected]>

Save this file as authors.txt.

Now we are going to do the magic to convert the repository. We first create a directory and initialise it as a git-svn frankenstein repository (the --no-metadata flag tells git to ignore all the SVN junk except the actual commit log). Then we slot our authors file in there to remap our users. Last of all we fetch the code (which might take a while).

Here we go (obviously change the repository location to your own):

mkdir my_project_svn
cd my_project_svn
git svn init --no-metadata
git config svn.authorsfile ../authors.txt 
git svn fetch

You might want to do away with the git-svn hybrid stuff so lastly we do a git clone of the directory we just created.

cd ..
git clone my_project_svn my_project

Now you have a pure Git repository. Do a git log to check that all of your project history still exists. If you are happy with everything you can rm -rf my_project_svn because it's not needed any more.

You can repeat this process for any other SVN repos that you want to convert to Git.