This is a supershort guide to migrate old SVN repositories to GIT, and from one GIT server to another…
SVN to GIT
I was using SVN to handle my research projects, then discovered GIT and it’s definitely another life. The are a few things that are different between the two systems, although some commands are similar, which may indeed be confusing. There are a billion of GIT tutorials on the web, but if you’re looking for a recommendation, I found this page from Bitbucket very nice!
So, you have many SVN repos and want to switch to GIT? I am going to assume you have very simple SVN repositories (one single branch, no tags) like I used to have. If you have a more complicated structure, have a look here and here.
You need the git-svn tool. It should be there by default, but if you don’t have you can easily install it from your package manager.
First, enter some directory in your local machine (e.g. where you keep all your geek stuff on GIT, say
Now, clone your old SNV repository using
git svn. Of course, you need access to it: in the example below I use the svn+ssh protocol, but you may have http here depending on your setup (just to be clear, this is the same link you used to checkout the SVN repo in the first place)
git svn clone svn+ssh://[email protected]/PATH/SVNNAME
SVNNAME are the coordinates of your SVN repo.
If you want a remote host (and believe me, you do!), you need to create a repository on some online service. I will use bitbucket in the example below (I like it a lot, mainly because it gives free unlimited everything to scientists!) but Github is also a popular choice. Assuming you have created a repository on the bitbucket website, just add it and push.
cd SVNNAME git remote add origin [email protected]:USERNAME/GITNAME git push origin --all
GIT to GIT
If you’re already a GIT convert, another useful thing I needed to do is migrate from one server to another (say from bitbucket to Github, etc). There are a million solutions if you google this problem, but this is by far the best one:
git clone --mirror [email protected]:USERNAME/OLD_GITNAME cd OLD_GITNAME.git git remote set-url origin [email protected]:USERNAME/NEW_GITNAME git push --mirror origin
Update: repo too big?
I recently tried to run these commands again, and found out one of my old svn repo was too big for either bitbucket or github. For instance, bitbucket has a soft limit of 1GB and a hard limit of 2GB… Just want to say that this tool called bfg is great to reduce a repo size while removing only some of the previous history.
That’s all folks, all previous history and commits are now safely stored in GIT. And of course, if you have troubles the following trick ALWAYS works: