Using git-svn with non-standard subversion repository layouts
Category: Blog

Today while working with a 3rd party’s codebase, I ran into a situation which git-svn could not directly handle without pulling in massive amounts of unnecessary repository history. Turns out the solution was much simpler than I anticipated, so I’m sharing here in case it’s useful for somebody else. The repository was as follows:

http://svn.domain.org/svn/trunk/<project_name> -- Production branch
http://svn.domain.org/svn/branches/<project_name> -- Development branch


I tried a number of approaches. First off, using the normal –stdlayout option with http://svn.domain.org/svn repository root to git-svn clone would have pulled in thousands of changesets from the repository which had nothing to do with the project I was working on.

Next I tried to use –trunk=trunk/<project_name> and –branches=branches/<project_name> and unfortunately this method tried to create a new branch for every child directory of branches/<project_name>. Obviously this wasn’t what I wanted either.

After doing a bit of searching on the web, I stumbled across another solution via this blog. Basically what it suggests doing is to use a separate svn-remote for the alternative path. This conveniently works around the issue quite nicely without any side-effects I’ve run into so far. Here’s the steps I followed:

  1. git svn clone http://svn.domain.org/svn/ –trunk=trunk/<project_name> <project_name>
  2. cd <project_name>
  3. vim .git/config
  4. Add an additional remote as follows:
    [svn-remote "svndev"]
    url = http://svn.domain.org/svn/
    fetch = branches/<project_name>:refs/remotes/dev
  5. git svn fetch svndev
  6. git checkout -b dev remotes/dev

After following those steps, you now have a new remote ‘remotes/dev’ which is a copy of the dev environment branch from the repository and a new local branch called “dev”. You should now be able to proceed like normal using your usual git-svn workflow.

Of course the obvious answer would be to use standard repository layouts or to not use Subversion and/or git-svn, but sometimes that’s not always an option. I hope this helps someone stuck in a similar situation. Also, please be sure and sound off in the comments if you find an alternative solution!

Update:
Here are a couple additional links which might prove useful depending on your desired workflow.

Tags: , , ,

2 Responses to “Using git-svn with non-standard subversion repository layouts”

  1. Jack says:

    Just wanted to say thanks for this. It didn’t get my layout working 100%, but it got me 80% of the way there and I was able to figure out the rest for myself. Thanks again!

  2. Dane S says:

    Thanks, this *does* help!

Leave a Comment

Spam Protection by WP-SpamFree