Introduction To Git-svn

This article explains how `git-svn` lets teams use familiar Git workflows on top of a Subversion repository when migration is not yet possible. It covers installation, cloning with standard SVN layout, and the core add/commit/ `git svn dcommit` cycle.

Coveros Staff

May 18, 2016

Subversion or SVN is a version control system that has been around for over 15 years and was the industry standard before the arrival of Git. Although Git is far superior to SVN, a lot of places are still tied to SVN for any number of reasons. I was exposed to and worked with only Git, until one of my projects was entrenched in SVN and there was no time to migrate to Git. Working with SVN when you know the capabilities of Git is a very strange and somewhat difficult experience. I often found myself wondering if there was a way I could script SVN to act more like Git. Luckily, someone had already solved this problem with the utility git-svn. Git-svn is a utility that mainly attempts to git’s local repository idea to a Subversion repository, and along with this comes all of the git commands you are familiar with. In this post, I will be going over how to install git-svn, clone a svn repo using git-svn, and the simple workflow of git-svn.

The first step to using git-svn is to install Git, SVN, and git-svn. If you are using linux, your package manager should be able to install all three tools. For example an Ubuntu user would install these through “apt-get”:

  1. sudo apt-get install git-core
  2. sudo apt-get install subversion
  3. sudo apt-get install git-svn

The next step is to clone the svn repository using git-svn, which can be done by:
git svn clone http://urlOfSubversionRepository.com -s

Notice the “-s” option which will use the standard SVN structure when cloning the repo. If your SVN repo has your branches in a branches directory, each one of those directories will become a git branch.

Now that the repository is cloned through git svn, you are now in a git repository! This can be confirmed by a simple “git status”. The next question that needs to be answered is, how do I work within this Git repo, but make sure my changes make their way into my SVN repo? This is done by the command “git svn dcommit” which you could insert anywhere you would do a “git push”. For example, you have two files that you have changed and want to commit to your svn repo. You would first do “git add file1.java file2.java” then “git commit -m “adding two files”” then you finally dcommit “git svn dcommit”. Now your changes from your local repository are stored in the remote svn repository. One thing to note here, if you do multiple git commits before you git svn dcommit, then all of the git commits will show up as one svn commit, and can get quite messy. There are many other advanced workflows and uses for git-svn that I will be covering in later blogs.

Coveros Staff

Coveros Staff

This post represents the collective insights of the Coveros team. Our staff consists of software experts who bring deep experience in secure agile development, DevOps, testing, and software quality. Over the past 20 years, Coveros has trained more than 30,000 professionals and worked with half of the Fortune 100 companies on mission-critical software development challenges. We draw on this extensive experience to share practical insights, proven strategies, and real-world solutions that help organizations build better software faster and more securely.