Importing a Git repository into a Subversion repository

In the following, we will assume that you have a Git repository in a directory named git.repo, with 3 commits in the master branch.

Step 1. Prepare the SVN repository. If it doesn’t exist yet, create it and run svnserve to make it accessible:

$ svnadmin create svn.repo

$ svnserve -d -r svn.repo

Then open svn.repo/conf/svnserve.conf  and set anon-access=write.

Now your SVN repository can be accessed via svn://localhost. If you already have an SVN repository, create a directory for a new project in it and use the SVN URL of that directory instead of svn://localhost for the rest of this tutorial.

SmartGit can handle repositories with the standard trunk/branches/tags layout, as well as repositories without any specific layout (i.e. just a directory with data in it). However, it’s highly recommended to use the aforementioned standard layout. Let’s create these standard directories:

$ svn mkdir svn://localhost/trunk svn://localhost/branches svn://localhost/tags -m "Initial structure."

Committed revision 1.

Step 2. With SmartGit, clone svn://localhost into a new directory. We’ll name it "svn.clone". SmartGit will autodetect an existing trunk/branches/tags layout and, if one exists, configure Git to map SVN branches to Git branches.

Step 3. Now you can transfer commits from your local Git repository at git.repo to your SVN repository at svn.clone:

$ cd svn.clone

$ git fetch /tmp/git.repo refs/heads/master:refs/heads/fetched
warning: no common commits
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (9/9), done.
From /tmp/git.repo
 * [new branch]      master     -> fetched

Now svn.clone contains all commits of the master branch from git.repo.

Step 4. We now need to apply these commits on top of refs/heads/trunk branch in svn.clone. This can be done with the Git rebase or Git cherry-pick operation. Here we’ll do this with rebase: Open svn.clone in SmartGit and select Branch | Rebase. Choose the "Selected commit(s) to HEAD" option. On the next page, select the commit marked with fetched. Make sure the "Commit Range" option is selected. Press Rebase.

Step 5. Push commits to SVN. To do so, simply press Push.

SmartGit tweets

Some SmartGit user feedback from twitter:

  • ldn_tech_exec: @aral smartgit is meant to be better than all those, but sourcetree my fav. GitHub for mac is too unstable and slow
  • Filip Vanderstappen: @GarethRedfern I think SmartGit is one of the best and feature rich apps for Windows.
  • Nathanael Jones: @cmsimike High reliability. I have 2 dozen repos, and I leave SmartGit running 24×7. It’s fast, smooth, intuitive. I don’t have to think.
  • Fahmi: ok, ‪#smartgit‬ was really awesome, very light and easy to use..
  • Ivan Zlatev: Failing to see the usefulness of @GitHub for Windows TBH. Pretty,but not functional for anyth. but commit and checkout. SmartGit however is.
  • Brian Franco: Well that’s odd. I couldn’t push my test app from git console or TortoiseGIT but it worked fine in Smartgit. I must’ve messed somethin up 😀
  • Fahmi:ok, ‪#smartgit‬ was really awesome, very light and easy to use..
  • Lex Li: Finally found a good GUI based Git tool on Linux http://www.syntevo.com/smartgit/quick … Free for non-commercial usage such as open source development
  • Ivan Zlatev: Failing to see the usefulness of @GitHub for Windows TBH. Pretty,but not functional for anyth. but commit and checkout. SmartGit however is.
  • James Eggers: A number of guys here in the office use SmartGit and love it. I’m a command line guy but from what I’ve seen it’s solid.