Skip to main content

Forking a Subversion Repository Using Git the Brutal Way

I work at a company. We use GitHub. There's a project called CoolProject. CoolProject uses Subversion. I want to fork CoolProject for internal use. There's no use submitting our patches back--they wouldn't want them. I want to maintain our own fork, but I also want to keep updated with changes that they make. Since Subversion isn't a distributed revision control system, forking like this and getting updates is hard. If you know of a better solution than the one I've proposed below, please tell me!

Git has support for Subversion. A great video on how to use it is here. The official documentation for git-svn is here. Here's the gotcha:
For the sake of simplicity and interoperating with a less-capable system (SVN), it is recommended that all git svn users clone, fetch and dcommit directly from the SVN server, and avoid all git clone/pull/merge/push operations between git repositories and branches. The recommended method of exchanging code between git branches and users is git format-patch and git am, or just 'dcommit'ing to the SVN repository.
Having each developer pull and manage their own repository and then share patches manually sounds painful. What I really want is to just check the source code into GitHub and have things just work. I asked on IRC what the best approach was, and I didn't get a response. I searched on the Web, and it seems like everyone using git-svn is working alone--i.e. using Git to work with an existing Subversion repository, but not trying to manage their own running fork with a group of people. I asked vark.com, and me and another guy came up with the following solution.

I checked out all of CoolProject's code from Subversion. I checked it into Git. I created a branch called coolproject_subversion that will be updated with updated with CoolProject's Subversion repository per the method below. My company will commit our changes to master. Once in a while, I'll merge changes from coolproject_subversion to master.

This is a brutally blunt method. We're losing all of Subversion's change history, all their commit messages, etc. However, it lets us keep up to date with their changes, and it lets us keep our own fork--as a group. It's the best thing I could think of. If I need to, I can always look at CoolProject's Subversion repository for log messages, etc.

I think it's a good idea to avoid munging with CoolProject's code as much as possible in order to avoid merge problems. The goal is to keep our code as isolated as possible, and only hack in some integration points. Okay, here's how I got started:
cd somewhere_in_my_git_repo
svn export http://coolproject.googlecode.com/svn/coolproject/trunk/ coolproject
git add *
git commit -a
git checkout -b coolproject_subversion
git checkout master
git push origin HEAD
git push origin coolproject_subversion
Here's how to grab changes from CoolProject's Subversion repository:
git checkout coolproject_subversion
rm -rf * # Double check where you are!
svn export http://coolproject.googlecode.com/svn/coolproject/trunk/ coolproject
git commit -a
git checkout master
git merge coolproject_subversion
git push origin HEAD
git push origin coolproject_subversion
Updated: Use "svn export" instead of using "svn checkout" and then deleting the .svn files.

Comments

Dougal said…
Rather than these two lines;
svn checkout http://coolproject.googlecode.com/svn/coolproject/trunk/ coolproject
find . -name .svn -exec rm -rf '{}' \;

Why not just do
svn export http://coolproject.googlecode.com/svn/coolproject/trunk/ coolproject

?
Rick Thomas said…
Hi Shanon,
Google Code has a recommendation here:

http://code.google.com/p/support/wiki/ExportingToGit
Thanks for the tip. It's well written, but it's written for the case of one developer using Git to interact with a Subversion server. I'm trying to have a team of people share an ongoing and updatable fork of a Subversion server. I think git-svn itself is the limiting factor :-/
raboof said…
This seems like a good approach to a recognizable problem/wish.

You'd say it should be possible to automate updating the coolproject_subversion branch, keeping the SVN commit messages intact even. Would be a wonderful feature for an online service such as gitorious or repo.or.cz .