Migrating from SVN to Git on MediaTemple (gs)

After seeing a video on using Mecurial on Codeplex I finally took the plunge into distribute revision control. Although Mercurial seemed to have better integration with Visual Studio, which is my main IDE, I decided to use Git instead. This decision was based purely on a gut feeling about which would be the best choice in the long run. If its good enough to write Linux with, it’s good enough for me.

The shift from SVN to Git was surprisingly easier than I expected. I remember SVN being a little frustrating to get going when I first started with that and was expecting a similar experience, especially when I was trying to shift a couple of in-progress projects from one to the other. What I did find however, is that the guides out there, although pretty good, did not quite match what I wanted to do. I thought I would jot it down so I don’t forget when I need to go it again. Its all done by logging into your server using putty or whatever your ssh client is. Lets jump straight in:

Git is installed on the (gs) so we can get straight into it. Firstly create a directly where you would like to keep your repositories:

mkdir /home/#####/data/git

Next create a temporary directory to store the git-svn export of your svn repository:

mkdir /home/#####/data/git/myapp_tmp

Next, create a text file (users.txt) to map your svn users to you git users. It should contain something like:

mysvnuser1 = Git User1 <gituser1@mysite.com>
mysvnuser2 = Git User2  <gituser2@mysite.com>

I saved mine to the /home/#####/data/git/ directory.

Next we initialise our git repository, ready to import the svn repository:

git-svn init file:///path/to/svnrepo/myapp/trunk/ --no-metadata

Note that I use the file:// notation to specify a local path to where my svn repository is kept. In my case it was /home/#####/data/svnrepo/ but it depends on how you set yours up. The no-metadata flag just ensures that only the information we need is transferred. We then need to setup our user mapping file:

git config svn.authorsfile /home/#####/data/git/users.txt

Now for the money shot, we import the data from svn:

git-svn fetch

All going well, your svn repository and all the history should have been imported into your git repository.

The final steps are done in order to tidy up your new git repository so that it is just a standard git repository, without all the svn associations. We remove the svn assocations by cloning it:

git clone myapp_tmp myapp.git

This gives you a myapp.git directory with the actual repository (everything in the .git directory) as well as your working files. As this is on the server, you do not need all the working files, just everything in the .git directory. We can fix that as follows:

cd myapp.git
mv .git .. && rm -fr *
mv ../.git .
mv .git/* .
rmdir .git
git config --bool core.bare true

Most of those commands just move everything out of the .git directory and remove the working files. The final command however marks the repository as a bare repository, i.e. one without the working files.

Thats it. You should now have a git repository on your server that you can clone to your development machine and begin work.


Leave a Reply

Your email address will not be published. Required fields are marked *