For the longest time I was a loyal Subversion(SVN) user. I know, it’s crazy, but I was. When I found out about Git, I was hooked immediately and used it for all of my personal projects. The problem was that at work we use SVN, and getting everyone to migrate to Git just wasn’t in the cards. Much to my surprise, Git has the ability to interact with a SVN repository, so I could still use it anyways.
The issue with my work’s current SVN layout is that it is non-standard. By that I mean all projects exist in one big happy repository. Something like:
Repository -> Project -> Trunk/Branches/Tags
Unfortunately, Git+SVN isn’t really all that excited about working with non-standard repositories, so I had to do some experimentation and Googling to figure it all out. Eventually, I came up with the following steps:
Step 1: Clone the Repo
The first step in this process is actually cloning your SVN repository. By clone, we mean make a full copy of it and all of the revision history.
git svn clone svn://the.svn.server/allEncompassingRepo/project -trunk=trunk/ .
After the initial clone is complete, we move to fixing where git should look for things.
Step 2: Set up fetch, branches, and tags
The initial setup for fetch, branches, and tags gets screwed up at this point if you have a non-standard layout like my employer does, so we need to do some cleanup. Open .git/config and set the following:
url = svn://the.svn.server/allEncompassingRepo
fetch = project/trunk:refs/remotes/trunk
branches = project/branches/*:refs/remotes/*
tags = project/tags/*:refs/remotes/tags/*
Now that the config file is all set, go ahead and save.
Step 3: Pull down your files
The config file is all set, so you’re ready to do your first pull.
git svn fetch svn
That’s all there is to it. If you’d like to know how to use Git+SVN, I suggest reading the fine article over at Viget.