svn-gitDigital Peak had all of it's Joomla extension code in Subversion repositories, as it was state of the art a couple of years ago. Nowadays Git is widly used under PHP developers and also Joomla itself stores it's code on Github. It was time for us to move to Git. Now we store our public code on Github and the private code on Bitbucket. As I'm a total newbie with Git, probably some steps can be made simpler but the migration explained below worked for us and I hope it will be of help for others too.

If you are not interested in the code histroy then just create a new Git repository and copy the most actual code, probably th SVN trunk to it. But we were interested in the full commit history so here are the steps to migrate your Subversion repository to to Git on an Ubuntu machine.

Setup the system

Install the needed packages from the Ubuntu:

$ sudo apt-get install git-core git-svn
$ sudo apt-get install subversion.
$ mkdir git
$ cd git/

Migrate the commiters

Subversion has a simple authoring system on the otherside Git uses the convention Name <email>. To convert the authors from Subversion to Git format perform the following steps:

$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

Then you have manually to adapt the file authors.txt to the new usernames. For example

laoneo = laoneo <laoneo>
laoneo = Lao Neo <>

Make the clone

This is the step where your SVN repository gets converted to the Git repository:

$ git svn clone --no-metadata -A authors.txt --stdlayout

Depending on your repository size it can take a while, but you should see on the screen step by step how each commit gets converted.

New bare repository

We create a new bare repository where the migrated repository gets merged into.

$ git init --bare new-repo
$ cd new-repo/
$ git symbolic-ref HEAD refs/heads/trunk

Push orig to the new one.

$ cd ../dpcalendar
$ git remote add bare ../new-repo/
$ git config remote.bare.push 'refs/remotes/*:refs/heads/*'
$ git push bare


Now we have to do some cleanup before we can push it to one of the online repositories. First we have to rename trunk to master.

$ cd ../new-repo/
$ git branch -m trunk master

The git svn command creates from the tags branches, means we have to create from them git tags and then delete the branches.

$ git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";

If you need to cleanup some invalid tags then do it now.

$ git tag -d Archive

Final push

If there doesn't need to be done more work on code we can push it to the online repository (if you want you can do ssh key exchange before).

$ git remote add origin
$ git push --all
$ git push --tags

Now we are done!!

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.