Migrating from svn to git

Recently I started looking around at GitHub and reading some tutorials on git. I decided to migrate some of my work related repositories from svn to git. This is the story of how that went. Basically this is explained on GitHub, but they leave out some details which might be needed for first-timers like me.

First of all, I had some difficulties getting everything installed at work, but those were quite specific to my system, so I won’t bother you with them. I still run Mac OS X 10.5.8 at work. This meant that the default git download didn’t work, and I had to look for an older version that had an installer for Leopard. Next I had to re-install Ruby and RubyGems in order to download svn2git.

I decided to use svn2git, since all my projects have trunk, branches and tags. I followed these steps for each project. I first created a directory for the project,  cd’ed into it, and gave the following command

$ svn2git http://svn.example.com/path/to/repo/nested_project --no-minimize-url --authors ~/authors.txt

I used this version of the command, because I have several projects in the same svn repository, and I wanted to use this occasion to split them. The authors file had been created as is explained on the svn2git site. Depending on the size and the number of commits to the project you’re migrating, this takes some time, but when this command returns the current directory will contain a local git repository. The next step is to set a remote for this repository and push the local repository to this remote. To do this you first create your repository on GitHub. Once you’ve done this (see the instructions on GitHub), you will see instructions on how you can set this repository as a remote for your local repository. Basically the command will look as follows:

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

Once that this is done, you can push your local repository to GitHub. It is this part that I found wasn’t explained well. I’m not even sure that what I have now is the best solution. The command that they give, is:

$ git push origin master

This only pushes the master branch (i.e. the trunk in svn terminology) to the remote repository. You need to repeat it for each branch:

$ git push origin branch1
$ git push origin branch2

If you’re not sure what all the branches are, you can list them using the following command:

$ git branch

Finally, you also need to push the tags to the remote repository. This can be done with the following command:

$ git push --tags

While typing this blog post and reading to the git manual again, I think you can group all the push commands using:

$ git push --all

But I’ll have to verify this first tomorrow.

Edit: It isn’t sufficient to use the --all option. This only pushes all the branches, not all the tags. So the correct commands to execute once you’ve set the remote repository is:

$ git push --all
$ git push --tags

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: