Move a repository from svn to git

02 Mar 2015

Reading time: 2 minutes

After recent company changes, it is becoming clear we are migrating some of our SVN repos to git. A collegues was kind enough to push the current codebase up to the shared git space, but sadly the import process lost the full history.

I was sure this should already be a solved problem and after a little research I found svn2git.

$ gem install svn2git

This allows a really simple syntax - just navigate to a fresh folder and run the following

svn2git http://svn.myserver.com/path-to-root/ --trunk Trunk --branches Branches --tags Tags

and watch your solution - every part of it - every commit gets streamed into the folder.

Then I started to process of uploading the lot. AFter setting up the repo on the new git remote server (blank of course) I added it to my local git directory

$ git remote add origin http://git.newserver.com/new/path.git

And then pushed to the new repo.

$ git push --all origin

Looks good - until 20mins later I get an error.

Unable to rewind rpc post data - try increasing http.postBuffer

It seems my full repo is over 100meg. It seems it didn’t want to work - so I tried the following….

$ git config http.postBuffer 209715200
$ git push origin --all

But I got the error again:

fatal: The remote end hung up unexpectedly

It seems that between the server and the network I was using - somethign was stopping the repo being uploaded. I realised that the repo wasn’t paticularly clean. Someone had been checking in IPAs, Zip files, PNGs - alot of dirty files that shouldn’t be there. I theorized that if I just fremove those files then it will allow me to commit - but it’s not a case of just swiping the files out. Git actually keeps a history of any file, so that it can be distrubuted with every instance of git. To wipe from the history I decided to use the BFG-Repo-Cleaner.

Drop the jar file into the solution folder and run it as follows.

$ java -jar bfg.jar --delete-files .ipa

Which helpfully told me…


Found 63 commits
Cleaning commits:       100% (63/63)
Cleaning commits completed in 334 ms.

Helpful. I ran this a few more times with various zip files, pngs that were never used, a storyboard that I didn’t need the history on and the pods directory (to do a directory use this:)

$ java -jar bfg.jar --delete-folders Pods

Eventually I got it under 70Meg and I tried once again to upload the git repo. This time I got a nice message telling me all the branches had been uploaded.