HowTo: Convert Subversion to Git

To make a start I can say that I personally prefer using Git as Version Control System. I use Subversion and Mercurial for some reasons too, but I do not really like to work with them.

Because of this I wanted to convert some Subversion repositories to Git. If you also have planned to do this, the following may help you.

Three different ways for the conversion:

  1. Copying the source code:
  2. The easiest and fastest way is simply copying the source code into an empty Git repository. For me this solution was impracticable, because you will loose the history.

    # Create and switch to new folder
    mkdir $GIT_REPO
    cd $GIT_REPO

    # Copy all files from the Subversion directory
    # Use -C option to ignore .svn directories

    # Do the Git steps
    git init
    git add *
    git commit -asm "Initial commit"

  3. Using git-svn:
  4. The next way to convert the repository is using git-svn. With git-svn you are able to adopt all branches and the whole history. The only unsuitable thing is converting tags, because they are created as branches by default and you need to switch them manually afterwards.

    # Install the software
    (sudo) apt-get install git-svn

    # Make and switch to new folder
    mkdir $GIT_FOLDER
    cd $GIT_FOLDER

    # Convert the repository
    git svn clone $SVN_URL --no-metadata --stdlayout .

    # Update the repository
    git svn fetch

  5. Using svn2git:
  6. Svn2git is a utility which uses git-svn internally to do the real conversion, but in addition it does some more jobs around this to perfect the system. With this you will have a accurate converted repository. It uses Ruby, so you need to install some additional packages.
    You can use svn2git for some special actions and custom purposes. If you need some more information you can take a look at the README.

    # Install the software
    (sudo) apt-get install git-svn ruby rubygems
    (sudo) gem install svn2git

    # Make and switch to new folder
    mkdir $GIT_FOLDER
    cd $GIT_FOLDER

    # Convert the repository
    svn2git $SVN_URL

    # Update the repository
    svn2git --rebase

I hope this tutorial helps you to save some time and troubles. If you have feedback, regards, corrections or questions please let me know and do not hesitate to comment!

I will probably write something about Version Control Systems, like a comparison or Cheat-Sheets, in other blog posts.

2 thoughts on “HowTo: Convert Subversion to Git

  1. Thanks for this nice tutorial, I’m sure I will use it some day ^^ Keep these posts coming, they’re very helpful =)

Leave a Reply

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



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>