SVN to Git migration that works

SVN to Git migrationSVN to Git migration is mostly about the following things:

  1. Migration of all branches and tags
  2. Saving complete history of changes
  3. Inheritance of commit author names

Fortunately there is an easy way to accomplish SVN to Git migration using git svn tool that comes as part of Git installation. This tutorial describes the entire process step by step.


Latest stable version of Git client require to be installed in your system. If your OS is Windows I would  recommended using Bash Git console.

Initialize new repository for SVN to Git migration

First of all we need to prepare new empty Git repository in your preferred directory.

Here we are initializing Git repository with standard SVN  directory structure (trunk, branches and tags). Additional SVN to Git migration related meta is created (including your SVN repository URL). Prefix svn/ is specified in order to separate remote SVN branches and tags from local (native) git branches and tags.

Fetch entire SVN repository

Depending on how big your SVN repository is it can take a while  to fetch it .

Technically the import can be considered done at that stage as everything is now in your new local Git repository. Let’s take a look what do we have there.

This command displays all local (Git) branches and remote (SVN) branches and tags.

Turn remote SVN branches to local ones

At that step we are about to create new git branches and tags from remote SVN branches and tags. This can be accomplished using standard git branch and git tag commands.

This process can be automated easily with a simple Bash script.

Let’s check the result of these operations.

As you can see now we have both old SVN and new Git branches and tags in the same Git repository.

Push all changes to remote Git repository

This is the last step of our SVN to Git migration exercise and everything is ready to be pushed to remote Git repository. First you need to tell Git where your remote repository is.

Then you can push all branches and tags. For some reason there is no single operation for this.

That’s pretty much all. SVN to Git migration is done! Now I would recommend to check remote repository content and clone it to another local directory. If everything looks fine you can safely abandon your temporary migration repository.

 SVN to Git migration is done. What’s next?

Note that all commit authors where migrated to Git repository as well. The only problem is that SVN user emails are not sent with SVN commits and Git generated random strings where emails where missing.

To fix this for future commits make sure all project members:

  1. Define the same username as they had in SVN
  2. Provide valid email

Happy commits!

If you are still looking for a good Git repository hosting provider check out comparison chart for best offers.

SVN to Git migration references

3 Responses to “SVN to Git migration that works”

  1. David says:

    If user just created a new folder and executed your commands :

    for branch in git branch -r | grep -v svn/tags | sed 's/ svn\///';
    > do
    > git branch $branch refs/remotes/svn/$branch
    > done


    git branch –all

    They probably will not able to see “*master” as selected branch. Plus the branch(es) will be empty until user will not checkout the new branch(es)

    git checkout trunk

    That step is missing.

  2. David says:

    Based on my experience after importing SVN branch directories I would like to move/rename trunk to some GIT sub-directory. By suing standard GIT move command I am loosing all my SVN history:

    git mv old_dir new_dir

    Instead I will suggest to use:

    git filter-branch –tree-filter ‘ls old_dir | xargs -i -t mv old_dir/{} new_dir | sh’ HEAD

Leave a Reply


Source repository hosting