Importing and Syncing a Subversion Repository with Git

Importing a Subversion repository is such a way that you may still sync the changes back in forth, is really just to simple. This how-to assumes you existing repository is running is SVN and you wish to switch it over to git.

Similar to how you may create a new SVN directory from a remote repo with svn, by running a command similar too:

svn checkout https://svn.example.com/svn/project_name

You may run the following to command to download the same remote repository, but then create an git repository and import the data from the svn repo.

git svn clone https://svn.example.com/svn/project_name

This will create a new directory named project_name with all your svn history.

Git is vary fast, but when it’s slow, it’s slow. The above process can take quite a bit of time (wordpress.org’s current trunk will take hours) to complete on an older (more comments not slower) repository since it checks in each comment at a time. If you don’t need the all the history of the project but just need a way to keep your self up to date as you code, you may just download the current revision tag.  So to  download SVN version 1234 and clone it into git, run:

git svn clone -r 1234 https://svn.example.com/svn/project_name

If you would like some of the history you can get that also, so if you would like say the last 234 commits run:

git svn clone -r 1000:1234 https://svn.example.com/svn/project_name

Then, to update your git repo once the SVN repository has been committed to, run

git svn fetch

That should ouput something like:

r1235 = 340621340d856d805714e9bd86fdb11777f710fe (git-svn)
 M    includes/deprecated.php
 M    includes/functions.php

You may now follow the Creating a secure git repository how-to and create a remote server.