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

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

http://code.google.com/p/support/wiki/ExportingToGit
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 repo.or.cz .

Popular posts from this blog

Drawing Sierpinski's Triangle in Minecraft Using Python

In his keynote at PyCon, Eben Upton, the Executive Director of the Rasberry Pi Foundation, mentioned that not only has Minecraft been ported to the Rasberry Pi, but you can even control it with Python . Since four of my kids are avid Minecraft fans, I figured this might be a good time to teach them to program using Python. So I started yesterday with the goal of programming something cool for Minecraft and then showing it off at the San Francisco Python Meetup in the evening. The first problem that I faced was that I didn't have a Rasberry Pi. You can't hack Minecraft by just installing the Minecraft client. Speaking of which, I didn't have the Minecraft client installed either ;) My kids always play it on their Nexus 7s. I found an open source Minecraft server called Bukkit that "provides the means to extend the popular Minecraft multiplayer server." Then I found a plugin called RaspberryJuice that implements a subset of the Minecraft Pi modding API for B

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

Creating Windows 10 Boot Media for a Lenovo Thinkpad T410 Using Only a Mac and a Linux Machine

TL;DR: Giovanni and I struggled trying to get Windows 10 installed on the Lenovo Thinkpad T410. We struggled a lot trying to create the installation media because we only had a Mac and a Linux machine to work with. Everytime we tried to boot the USB thumb drive, it just showed us a blinking cursor. At the end, we finally realized that Windows 10 wasn't supported on this laptop :-/ I've heard that it took Thomas Edison 100 tries to figure out the right material to use as a lightbulb filament. Well, I'm no Thomas Edison, but I thought it might be noteworthy to document our attempts at getting it to boot off a USB thumb drive: Download the ISO. Attempt 1: Use Etcher. Etcher says it doesn't work for Windows. Attempt 2: Use Boot Camp Assistant. It doesn't have that feature anymore. Attempt 3: Use Disk Utility on a Mac. Erase a USB thumb drive: Format: ExFAT Scheme: GUID Partition Map Mount the ISO. Copy everything from