From Assembla to GITHub – Phase 1: Migrate your SVN repository to GIT

I recently migrated my Assembla abap2xlsx to GITHub ( #abap2xlsx is relocating… Welcome to GITHub ) and I would like to share a quick “how to” just in case you want to migrate also your SVN repository to a GIT repository maintaining all the history.

Prerequisite

  • GIT installed on your machine, if you’re using GITHub you can install their Client
  • Having an SVN repository to migrate 

Let’s start our journey

Preface

Unfortunately, I switched to a Windows PC right now, so most of the screen shots and commands are referred to a windows machine, I’ll try to give you the same details also for Mac o Unix/Linux.

Chapter 1 – Prepare for migration

The first step is to prepare everything in order to have a smooth migration, in this case we need to create a file with the list of all the contributors of the SVN project, this file will be used in the next step to match users in repository history.

Using your console/shell move into the root of your SVN project

If you’re not in a windows machine

svn log -q | awk -F ‘|’ ‘/^r/ {sub(“^ “, “”, $2); sub(” $”, “”, $2); print $2″ = “$2” <“$2″>”}’ | sort -u > USERS.txt

On windows you have to install sed – the stream editor, simple copy sed.exe in the current folder (I’ll make this step simple, you can also add sed in your PATH) and then execute

svn log –quiet –xml | sed -n -e “s/<\/\?author>//g” -e “/[<>]/!p” | sort | sed “$!N; /^\(.*\)\n\1$/!P; D” > USERS.txt

The file is the list of all contributors that had made at least a commit to the repository. We need now to edit this file in order to make it like the snipped below, please pay attention to the charset otherwise the next steps will fail (never trust Notepad)

Alessandro Iannacci = Alessandro Iannacci <aiannacci@xxxxx.it>
gregor.wolf = Gregor Wolf <gregor.wolf@xxxxx.com>
IvanFemia = Ivan Femia <ivan.femia@xxxxxx.com>
JOACHIM.WRBA = Ivan Femia <ivan.femia@xxxxxx.com>
Ludek.Vondruska = Ludek Vondruska <Ludek.Vondruska@xxxxxx.cz>
p491969 = Ivan Femia <ivan.femia@xxxxx.com>
stefan_schmoecker = Stefan Schmöcker <schmoecker@xxxxxx.de>
Tomek Mackowski = Tomek Mackowski <tmackowski@xxxxx.com>
turnheim = Rene Turnheim <rturnheim@xxxxxx.com>
www-data = Ivan Femia <ivan.femia@xxxxxx.com>

Chapter 2 – Convert SVN repository

GITHubOpen your GIT shell and start the conversion…

Really easy? No this command depends on your SVN structure, so it depends on the TRUNK, BRANCHES, TAGS folders.

From GIT console move on a directory that you want to use a working dir and then execute the following command:

git svn clone [SVN repository URL] -A USERS.txt –stdlayout ~/temp

on a Windows machine I suggest to use /temp instead of ~/temp

This command it’s great  if you have a standard SVN layout, with all the three SVN folders; in my case, for example, I had only the trunk as a root so I executed

git svn clone [SVN repository URL] -A USERS.txt –trunk=/trunk /temp

For more information on git svn command please refer to the official documentation

Chapter 3 – Convert svn:ignore to .gitignore

From the GIT console execute this simple steps

cd temp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m ‘Convert svn:ignore properties to .gitignore.’

It will convert the SVN ignore properties in the GIT ignore and add it to the commit.

Chapter 4 – Create the bare repository

Now we need to create our bare repository (.git folder) that will be imported in our Code Repository (e.g. GITHub)

git init –bare ~/your_project_name.git
cd ~/your_project_name.git
git symbolic-ref HEAD refs/heads/trunk

push the content into this bare repository

cd ~/temp
git remote add bare ~/your_project_name.git
git config remote.bare.push ‘refs/remotes/*:refs/heads/*’
git push bare

and link the trunk as master of the git bare

cd ~/new-bare.git
git branch -m trunk master

Chapter 5 – Gran finale: import into your Code Repository

You are now ready to import the .git bare folder into you git repository (in this case GITHub). Make sure that you have created a repository on GITHub with the same name of your bare folder.

cd your_project_name.git
git push –mirror https://github.com/your_user_name/your_project_name.git

and delete temporary folder

cd ..
rm -rf your_project_name.git

Epilogue – Enjoy

Enjoy GITHub!

In the next blog I will describe how to import issues, comments and milestone from Assembla to GITHub.

Leave a Reply