Save Expand icon

Ron Valstar
front-end developer

Migrating a subversion repository from Google Code to Github

Recently I migrated TinySort from Google Code to Github. I’m a real Git noob so I expected a full history migration to be a real pain in the ass. Plus I also wanted to move both the open and closed issues (since they correspond to the regression tests). Luckily it turned out to be a lot easier than I anticipated.

Unlike what Github says you should do to migrate I started at Google Code itself. Google Code also supports Git and they have excellent instructions to convert your existing Subversion repository into a Git repository.

Since my project didn’t have any tags the Google Code instructions sufficed. If your project does have tags and you want to convert them properly you might be better off following Githubs suggestion to use the svn2git tool (there’s also the git-svn-migrate tool, I have no idea which is better). My main reason for not using svn2git was that it requires Ruby. And although I think I have that installed I didn’t want to overcomplicate things because I already didn’t know what I was doing learing Git and all.

Once you’ve followed the instructions you should have a checkout of your project on your local machine. Now all that is left is to move it to Github.

I’m mainly using Git Bash here but I also have Tortoise Git installed and Githubs own Windows client (although the latter sucks a bit).

Presuming you have a Github account and created an empty project to push the lot into; you first have to add the Github remote to the project (Unlike Subversion a Git project can have multiple locations called ‘remotes’):

$ git remote add origin git@github.com:GITHUB_USERNAME/REPO_NAME.git

You can check yourself we now have two remotes: googlecode (you added earlier) and origin.

$ git remote
googlecode
origin

Before we can push to Github (origin) we must do a pull. And since origin is not our default remote (googlecode is) we must also specify which branch to pull from (the master branch).

$ git pull origin master

Since your repo is now up-to-date you can push:

$ git push --all origin

…and that’s it!

Now for the issues, this proved somewhat more laborious. This piece of Python code does the trick. I speak as much Python as I speak Japanese so I hardly bothered checking the code. I only added my login data, altered it to move everything instead of only the open issues and commented out ln 13 ‘from __future__ import print_function’ since that line prevented it from running.

This worked with only two minor mishaps: all thirty or so closed issues I had were now open on Github and all issues on Google Code were now tagged ‘migrated’ and open. For the latter I just added the migrated tag to the closed issues list on Google Code. On Github I just closed the issues by hand.
So next time I’ll try to alter the script a bit to actually close the closed issues (also some good Python practice for me).