Migrating to Git from SVN

Is your current Subversion (SVN) version control system not meeting the needs of your development team? Perhaps you’ve heard of Git, but you’re so entrenched in SVN, that converting to a new version control system seems like a daunting task. Fear not! No task is insurmountable when you have the power of the legendary GitKraken on your side.

Let’s take a look at why you should consider migrating to Git from SVN, and how you can best accomplish the task—with a little help from your friend Keif the Kraken.

Advantages of Git

Popularity – Git is the most widely-used version control system in the software development space right now. According to Stack Overflow’s 2017 Developer Survey, over 70% of professional developers are using Git. This means that adopting Git in your company will not only get you onto the preferred version control system in the industry, but it will also decrease the time it takes for new developers to learn your system.

Distributed Version Control – Git uses a distributed method for version control, which is a stark contrast compared to SVN’s centralized method. This means that each user clones a full version of the repository to their local machine, which is advantageous in several ways. It removes the single point of failure of the centralized repository, reduces network traffic for day-to-day operations, and allows your team to work offline.

Size and Speed – Arguably the strongest reason to migrate to Git is branching and merging. Creating a branch is effortless and is extremely lightweight, allowing your developers to work faster and merge easier.

Here’s a quick recap:

Migrate to Git from SVN

Praise the Kraken! You’ve decided to move ahead with your SVN to Git migration. So, what’s the next step? Planning is always a good thing, and Microsoft has put together a comprehensive checklist of the things to consider when migrating your team over to Git.

Once you’ve completed your planning phase, it’s time to actually start migrating your code. The complexity of the migration depends on several things: the complexity of your SVN repository, how many merges you have done, and whether or not you care about reformatting the history from your SVN repo.

Reformatting the history involves the following additional steps:

Converting the commit username to first and last name, with an email address

Removing some additional SVN-specific metadata

Migrating the svn:ignore file to a .gitignore file

Converting your SVN tags over to git tags

Migrating all of your SVN branches over to your new Git remote

If you’re not concerned with preserving the objects above, go ahead and proceed with the instructions below. If you do want to migrate all of that historical data, jump down to the import and preserve history instructions.

Start Fresh

If you’re not worried about reformatting the history from your SVN repository, then the conversion process just got a whole lot easier! Git has a built-in git svncommand for cloning an SVN repository into a new Git repository. You would simply run:

git svn clone <SVN_URL> -T trunk -b branches -t tags

Grab some coffee…

This process can take some time because Git is taking each commit from your SVN repository and processing it again using Git.

Once the command completes, go ahead and open this repo in GitKraken and you should see a nice graph of your newly converted Git repo.

At this point, you can jump down to setting up your new Git remote, and you’re just about done!

Import and Preserve History

The import by `git svn` does a valiant job; however, there are some additional steps that can be taken to perform a more accurate import that cleans up and reformats the history information to look more like Git history.

First, let’s look at the author information. SVN tracks commits using a username, whereas Git has a full name and email address. You can run the following bash command in the working directory for your SVN repository to output a list of your SVN authors:

You will now need to edit each author in the author-transformed.txt file to match the syntax you need for your Git author information.

For example:

ryanp = ryanp <ryanp>

Becomes:

ryanp = Ryan Pinkus <ryanp@example.com>

Now that you have your list of authors ready, you can run the import using git svn and specify the authors-transform.txt. Copy the authors-transform.txt to a new directory C:/repo/temp and cd to that directory in the CLI.

*Note: If you are seeing a blank Git repository after this command completes, then you might not have a standard layout in your SVN repo. Try removing the--stdlayout flag.

That command will clone the SVN repository to a new Git repository in the “temp” folder of your repo directory. If you open the repo in GitKraken, you will see that the commits are now in the Git format.

Next, you will want to address the svn:ignore file, if you were using one. You can run the following commands to convert the svn:ignore to a .gitignore file and commit it to your new Git repository.

cd c:/repo/temp/your-project
git svn show-ignore > .gitignore

You should now see the .gitignore in your WIP node in GitKraken. Go ahead and commit the new .gitignore to your repository.

Next, you’ll want to convert all of the SVN tags into the proper Git tags. You can run the following command to do so:

Once again, you can use GitKraken to view all of your branches and clean up any that you no longer need. If you still see a “trunk” branch, verify it’s pointing to the same commit as “master”. If so, you can go ahead and delete that branch, because you will now use the “master” branch, instead. Right-click the branch name in the left panel and select “Delete trunk”.

Your local repo should be ready to go at this point; so you can create your remote and push the repo up to your local repo.

Set Up Your New Git Remote

If you’re using a service like GitHub, you can use GitKraken to create the remote. Uncheck the Clone after init option, to only create the remote repo.

You’ll need the URL for the new remote repo, so click the View on GitHub.com button.

Copy the URL to the repo and go back to your local repo in GitKraken.

Click the + icon in the Remote section of the left panel.

On the URL tab, name your new remote, paste the URL to the repo into the Pull and Push URL fields, and click Add Remote.

You can now right-click each branch and tag to push them up to your remote.

If you have a large number of branches or tags, then you can use the following commands to push them up to your remote.

git push origin --all
git push origin --tags

Congratulations!

You should now have a functioning Git repo. Here are some additional resources for getting started with Git and GitKraken: