Migrating SVN to Git with history

I’ve been using Git more and more lately, mostly because it allows me to do lots of checkins locally, even when disconnected, and then push those centrally when I get back online.

I’ve just gone through the process of migrating all my public and private SVN repositories to github (for the public ones) and BitBucket (for the private ones). A one-way migration is not that difficult, but a one-way migration with all the checkin history, branches and tags proved to be a little more involved.

After a few false starts I found this post, which worked almost entirely, except for the section “Getting a bare repository onto the server”. The command:

git clone --bare mscn_temp mscn.git

(or the equivalent with my repository names substituted) produced something that I could not get bitbucket to recognise. This may be down to my relatively low git-fu, however eventually I dropped the .git on the end of the new repository name and then I could proceed.

The second problem in that same section is where he says “Upload your bare repository to your server wherever you would like. Do this with the tool you are used to to upload stuff to your server.” Well, I’m not that used to uploading bare repositories, so I needed some help. Eventually, the BitBucket docs and StackOverflow came together to get me the following:

git remote -v

showed me that I still had a remote link called origin to my temporary git repository into which I’d imported the svn repository. I removed this with:

git remote rm origin

I could then add a new one pointing to the new, empty, bitbucket repository with:

git remote add origin ssh://git@bitbucket.org/username/repositoryname

(substituting in my username and repository name of course).

This allowed me to finally push the master branch up to bitbucket with:

git push -u origin master

3 Comments

    • ¬†@pjblog¬†Nice. Looking at it ,it pretty much does the same steps as the referenced article. I ended up scripting the steps as I had a number of repositories to do, however this looks like a good alternative.

  • […] moving my sample code from google code to github, I’ve had a few people complain that now they can’t open the source from within the IDE […]

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">