Convert your svn repository to git on Mac Lion

While working on Tiki Kaboom and another upcoming title, Russ and I determined that we wanted to change from our own hosted Subversion repository to a git repository.  We also decided there’s no reason whatsoever for us to be in the server business–especially when there are solutions out there like bitbucket.  I searched the web for good sites on how to do this, but it was so much simpler than any site I found, although most of what I will explain is taken from this site:

Here is the step-by-step process:

  1. You should already have the following prerequisites installed: git-svn, git-core, ruby, rubygems.  If you want to make sure, you can check this by typing the following in the terminal:
    $ git --help
    $ git svn --help
    $ ruby --help
    $ gem --help

    These all should be installed by default on a Mac Lion machine that has xcode installed.  You should get valid help messages for each one.

  2. Install svn2git.  You can install svn2git through rubygems, which will add the svn2git command to your PATH. Here’s how:
    $ sudo gem install svn2git
  3. Create an authors.txt file. This will be used to create the comment history in the new git repository.
    $ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); \
    sub(" $", "", $2); print $2" = "$2" <"$2">"\
    }' | sort -u > authors.txt
  4. Create the new git repository. You need to create the directory where you would like it to resolve and change to that directory to run the following commands:
    $ cd /path/to/new/git/repo/
    $ svn2git \
    --authors /path/to/authors/txt/authors.txt \

    The authors.txt file is the one you created in step 3. Adjust the path appropriately.


    If you get errors, you can find additional options in the svn2git README file. For example, I also had to use the --rootistrunk option because the root level of our svn repo is equivalent to the trunk and there are no tags or branches. I found this out when I got the following error:

    svn2git 'master' did not match any file(s) known to git.

    The --rootistrunk option did fix the problem, but I had to delete the .git folder and all files underneath it before running again. After any failed attempt, you’ll probably need to delete the .git folder before retrying.

  5. Done! You’re ready to push to bitbucket or github!

Thanks to the following for their help with the above. Everything I learned above was due to fellow developers sharing their knowledge. Here are some of the sites I used most: