Export SVN to Git

18 July 2014

This article explains the fastest and easiest way to export an SVN repository to Git.  There are lots of explanations of this online but none handle complex SVN folder structures well.

Simple versus complex SVN folders

If your SVN repository has only trunk, branch, and tags you can use the standard export command:

git svn clone -r0:HEAD --follow-parent --prefix=origin/ --stdlayout http://svn.com/svn/project

But if your repository starts in a subfolder or has branches in subfolders this process will break. For example:

http://svn.com/svn/ourcompany/project/trunk
http://svn.com/svn/ourcompany/project/branches/features/newlogo
http://svn.com/svn/ourcompany/project/branches/bugfixes/updatelogin

The complete process

[svn-remote "svn"]
url = http://svn.com/svn/ourcompany
fetch = project/trunk:refs/remotes/svnorigin/prod
fetch = project/features/newlogo:refs/remotes/svnorigin/feature_newlogo
fetch = project/bugfixes/updatelogin:refs/remotes/svnorigin/bugfix_updatelogin
git svn fetch > clonewars.txt
git remote add github https://github.com/MyCompany/project.git
git push github --all

How to empty a Github repository entirely without deleting it

If you make a mistake and need to clear github entirely do this in a new folder:

git init
(Add an empty file and commit it)
git remote add github https://github.com/MyCompany/project.git
git push github --mirror

Add issue numbers in commits like TortoiseSVN

Finally, if you want to add numbers to commits in TortoiseGit put the following section in your new repository's /.git/config file:

[bugtraq]
url = http://jira.mycompany.com:8080/browse/%BUGID%
number = false
warnifnoissue = true
message = http://jira.mycompany.com:8080/browse/%BUGID%
label = Issue number
append = false