Moving from SVN to Git

The goal of this sec­tion is only pro­vide an overview of the options avail­able to migrate from SVN to Git. The com­plex­i­ty and amount of time it takes to migrate from SVN to Git will depend on the size of your repos­i­to­ry and the amount of users you have.

There are two ways to approach mov­ing to Git from Subversion. 

  • Bridg­ing
  • Ful­ly Migrating

Let’s look at each one in a bit more details.

Bridg­ing Git to SVN#

Bridg­ing Git to SVN means run­ning a Git repos­i­to­ry local­ly while push­ing your changes to an SVN repos­i­to­ry. This set­up allows you to work with Git com­mands local­ly while keep­ing your repos­i­to­ry as SVN. It’s a client tool (Git) that inter­acts with a SVN server.

How­ev­er, you are lim­it­ed to what you can do. All of your changes and oper­a­tions need to be trans­lat­ed to SVN commits. 

To get start­ed with bridg­ing Git to SVN, you first need to clone the remote SVN repos­i­to­ry and import it as a local Git repos­i­to­ry. You do that using:

$ git svn clone <repository URL> project_folder

After mak­ing changes, you still use git-committo com­mit your changes:

$ git commit -am "my new changes"

How­ev­er, this com­mit is still only in your local Git repos­i­to­ry. We need to push it up to the SVN repos­i­to­ry. To do that we need to use a spe­cial git-svn bridge com­mand called dcommit:

$ git svn dcommit

This cre­ates an SVN com­mit for each Git com­mit and then rewrites the local commit.

If you need to pull down changes from the SVN repos­i­to­ry in to your local Git repos­i­to­ry, you can do that using rebase. But it’s a spe­cial ver­sion of rebase using the git-svn bridge.

$ git svn rebase

This pulls down the com­mits from SVN and replays them, sav­ing them as git commits. 

For full doc­u­men­ta­tion on how to bridge Git to SVN, please refer to the offi­cial Git doc­u­men­ta­tion.

Migrat­ing An SVN Repos­i­to­ry to Git #

You may want to move over to Git com­plete­ly and not both­er with the bridge comm­nds. To do that, you need to migrate the repos­i­to­ry to a local Git repos­i­to­ry using the git svn clone com­mand. This is the same com­mand we used in the first step of bridg­ing Git to SVN.

$ git svn clone <url> project_folder

The time it will take to clone the SVN repos­i­to­ry will depend on the size of your SVN repos­i­to­ry. After you clone the repos­i­to­ry you should then push to a remote, assum­ing that’s the work­flow you want to build for your team.

One note on migrat­ing: the offi­cial doc­u­men­ta­tion rec­om­mends that you first export your SVN users and include them as part of the clone com­mand. This will result is clean­er com­mit data. Refer to the offi­cial doc­u­men­ta­tion for more infor­ma­tion on the exact steps to do this, includ­ing how to migrate remotes and tags.