This page tells you how to convert an svn repository to Git. If you follow these instructions, you should have no intent of ever returning to svn. If you just want to use Git to interact with an svn repository, without permanently converting anything, see git-svn.

Convert the Repo

Here's the command you'll use:

   git-svn clone --stdlayout --no-metadata  --authors=/tmp/authors svn://svn-repo new-git-repo-name

Supply your own authors file, svn repo name, and the name of the directory that should be created to contain your git repo.

--no-metadata means that you're importing to git once and for all. Otherwise, it adds git-svn-id lines to every commit message, allowing bi-directional svn usage but cluttering up your project's history. Of course, some people actually want the git-svn-id lines because they claim it helps with code archeology. Up to you.

stdlayout

If your git-svn doesn't support --stdlayout, you definitely need to upgrade (even if you don't intend to use it!).

--stdlayout just means, "import the trunk directory to the git master branch, and create remote tracking branches for the branches and tags directories."

To see if your repo uses the standard layout, run svn ls repo-url, i.e. svn ls file://localhost/tmp/repo. You should see

   branches/
   tags/
   trunk/

You can also use --branches, --tags, and --trunk to specify the directories

Authors

The /tmp/authors file attaches svn usernames ("bronson") to the corresponding Git full name and email:

   bronson = Scott Bronson <bronson@example.org>
   detch = John Detch <detch@example.com>

Now you should know enough to be able to run the above command.

Clean Up

It makes sense that git-svn turns your svn tags into remote tracking branches... but why does it do the same thing for tags? Why not just turn a svn tag into a git tag?

Because svn thinks that branches and tags are the exact same thing. Because git-svn needs to maintain two-way communication, it's not interested in converting them, then undoing the conversion every time it pushes.

It's easy enough to fix. Anyone want to write a script?

   git tag v0.92 tags/0.92      # tag the branch
   git branch -r -d tags/0.92   # and delete it
   git tag v0.94 tags/0.94
   git branch -r -d tags/0.94
   ... etc

And there's no use for the trunk branch any more.

   git branch -r -d trunk

Finally, it leaves an svn directory in the .git directory. You can just rm -rf .git/svn, but you'll leave this behind when you clone the repo elsewhere.

You're done!

Not stdlayout?

Importing "branches", "tags" and "trunk" is easy. But what if you have some other directories that you'd like to import?

My repo was:

   branches
   tags
   trunk
   tmtest-0.8

I want tmtest-0.8 to be in its own branch in the new repo. There's no way to do this with the git-svn command but there's a trivial workaround.

First, import branches, tags, and trunk using --stdlayout as shown above. This creates the master tmtest repository.

   git-svn clone --stdlayout --no-metadata  --authors=/tmp/authors svn://repo tmtest

Now clone the tmtest-0.8 branch into its own temporary git repo (no --std-layout because we only want to operate on the single branch):

   git-svn clone --no-metadata  --authors=/tmp/authors svn://repo/tmtest-0.8 tmtest-0.8

And, finally import the master branch of the temporary repo into a new branch in the final repo:

   cd ../tmtest
   git fetch ../tmtest-0.8 master:tmtest-0.8

Oh, right, you can delete the temporary repo

   rm -rf ../tmtest-0.8

So easy!