SVN to GIT Migration Complete Tutorial With Examples

I have worked with SVN for a long time and recently I have started working on Git. After getting familiar with Git, I can clearly say that it’s far better than SVN. If you work with multiple branches and take a merge between branches or reintegrate (svn terminology) then you will know the benefit of Git over SVN.

I have recently moved my Google Code project to Github since google code is closed, so I thought to write a tutorial on SVN to Git Migration.

First we will look into using Git native commands to migrate the SVN repository to Git repository and then see what are the drawbacks and then we will do the same thing with SVN2Git tool.

SVN and Git Repositories Details:

Git Native Commands for SVN to Git Migration

  1. First step is to create the authors file from the SVN commits, below is the command for that. We need this file for git migration. It’s a big command, make sure you put all these in a single command.

    After this, you will have authors.txt file that will have all the authors details who have committed code into this SVN project.
  2. Find the revision number at which project was created. Use command below:

    You will get the first revision number, if you have a bigger project with release cycles and you are importing from specific release, then this number could be something different. For me it’s 1 because I just created this sample SVN project for this tutorial.
  3. Run below command to use git svn clone to convert your SVN project into Git. Use revision number when your project repository was created.Passing –no-minimize-url will allow git svn to accept URLs as-is without attempting to connect to a higher level directory.

    For other options, read git-svn documentation.

  4. You will have the project directory created, go into that and add remote git url as origin.

  5. Converting SVN Branches to Git Branches: If you will list branches at this time, you will get something like below.

    Git svn clone command makes master from trunk that is ready to be pushed to remote git repository. But we want to push branches too. Use below commands for that:

  6. Migrating Tags: Git svn clone command doesn’t create tags, follow below commands for creating tags and make them ready to push to remote.

  7. Pushing Git Branches and Tags to Remote: My master, branches and tags are ready to be pushed, use below git push command to publish them to remote repository.

That’s it. We have moved our SVN project to Git. While this process seems easy, there are two drawbacks with git svn clone.

  1. It doesn’t create branches for us to push to remote repository. There is a manual work involved, imagine you have 20 branches. It will take a lot of time to create branches and there are chances of errors or typos.
  2. No support for tags, I had to checkout the tag as branch and then create tag from it. This is not like moving tags from SVN to Git.

SVN to GIT Migration using svn2git tool

svn2git tool solves above two problems with native commands. Before we use this tool, we need to install it. It requires git, git-svn, and ruby installed. svn2git is a ruby wrapper around git’s native SVN support through git-svn. You can install the pre-requisites using below command.

  • Once you have the necessary software on your system, you can install svn2git through rubygems, which will add the svn2git command to your PATH.

    Once svn2git is installed, use below commands to migrate SVN repository to Git.

    1. First create the authors file using above command.
    2. Find the initial svn revision from above svn log command.
    3. Use below command to create local git project from svn repository.
    4. Pushing Branches and Tags to Remote Git Repository: You will notice that svn2git has already created Git branches and tags for you to push to remote. Just add the remote origin and push whatever branches and tags you want to remote repository.

    That’s it. We have migrated SVN repository to Git using svn2git tool. There are various options that we can use with svn2git, for example –notags if you don’t want to migrate tags. Please go through svn2git Usage section for various options. Also note that README.txt file that was not part of standard svn structure is not migrated.

    That’s all for svn to git migration. Based on above analysis, svn2git tool seems a better choice to me than git svn clone native command.

By admin

Leave a Reply