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, 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 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 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.


Dougal said…
Rather than these two lines;
svn checkout coolproject
find . -name .svn -exec rm -rf '{}' \;

Why not just do
svn export coolproject

jjinux said…
Rick Thomas said…
Hi Shanon,
Google Code has a recommendation here:
jjinux said…
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 :-/
Unknown 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 .

Popular posts from this blog

Ubuntu 20.04 on a 2015 15" MacBook Pro

I decided to give Ubuntu 20.04 a try on my 2015 15" MacBook Pro. I didn't actually install it; I just live booted from a USB thumb drive which was enough to try out everything I wanted. In summary, it's not perfect, and issues with my camera would prevent me from switching, but given the right hardware, I think it's a really viable option. The first thing I wanted to try was what would happen if I plugged in a non-HiDPI screen given that my laptop has a HiDPI screen. Without sub-pixel scaling, whatever scale rate I picked for one screen would apply to the other. However, once I turned on sub-pixel scaling, I was able to pick different scale rates for the internal and external displays. That looked ok. I tried plugging in and unplugging multiple times, and it didn't crash. I doubt it'd work with my Thunderbolt display at work, but it worked fine for my HDMI displays at home. I even plugged it into my TV, and it stuck to the 100% scaling I picked for the othe

ERNOS: Erlang Networked Operating System

I've been reading Dreaming in Code lately, and I really like it. If you're not a dreamer, you may safely skip the rest of this post ;) In Chapter 10, "Engineers and Artists", Alan Kay, John Backus, and Jaron Lanier really got me thinking. I've also been thinking a lot about Minix 3 , Erlang , and the original Lisp machine . The ideas are beginning to synthesize into something cohesive--more than just the sum of their parts. Now, I'm sure that many of these ideas have already been envisioned within , LLVM , Microsoft's Singularity project, or in some other place that I haven't managed to discover or fully read, but I'm going to blog them anyway. Rather than wax philosophical, let me just dump out some ideas: Start with Minix 3. It's a new microkernel, and it's meant for real use, unlike the original Minix. "This new OS is extremely small, with the part that runs in kernel mode under 4000 lines of executable code.&quo

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and Haskell is elegant and beautiful. It's been successful in various programming language competitions. I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which? Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both p