Brizzled: Getting Subversion and git to play well together

Brian M. Clapper, bmc @ clapper.org

Article URL: http://brizzled.clapper.org:80/id/81
Published on: 10 September, 2008


In One case for git, I talked about a natural fit between a problem I encountered and the git distributed version control system.

As it turns out, I can still get all the benefits of git, even though we're not in a position at work to convert from Subversion to git. I recently converted my home Subversion repositories to git, using the git-svn tool. But that was just one use of git-svn. The primary purpose of that tool is to provide "bidirectional operation between a single Subversion branch and git".

Basically, git-svn creates a cloned git tree from a Subversion repository. It stashes metadata about the Subversion repository in the resulting git repository. git ignores the metadata, but it's there for git-svn to use.

If you just want perform a one-way migration from Subversion to git, you can use git-svn to do so, telling it not to store the metadata. That's how I migrated my personal Subversion repositories to git. But that's not what I want to do here. Instead, I want a git repository I can use locally, but that also permits me to push my changes up to the corporate Subversion repository when I'm ready.

Doing that is surprisingly easy.

First, I used git-svn to clone our repository:

$ git-svn clone svn+ssh://bmc@svnhost/usr/local/svn/development \
  -T svn+ssh://bmc@svnhost/usr/local/svn/development/trunk \
  -t svn+ssh://bmc@svnhost/usr/local/svn/development/tags \
  -b svn+ssh://bmc@svnhost/usr/local/svn//development/branches

Our repository is large; that command took more than a half-hour to run. When it finished, though, I had a complete local git clone of our Subversion repository. While working on something yesterday, I found I needed to test it using a local VirtualBox test instance. I was easily able to clone my local git repository and synchronize on the VirtualBox instance. As I made fixes on my development machine, I just used git-commit to commit them to my local repository and git-pull to pull them to the VirtualBox test instance. And git-pull is pretty damned fast.

Later, when I was ready to push my code to the Subversion repository, I simply typed:

$ git-svn fetch    # make sure local repo is up-to-date
$ git-svn rebase
$ git-svn dcommit

git-svn pushed my local commits up to the Subversion repository in one (quick) operation.

To update my local repository from the Subversion repository, I use:

$ git-svn fetch
$ git-svn rebase

For those stuck between git and Subversion, git-svn can be a near-perfect solution.