Thursday, December 13, 2007

Using Git with SVN

I've been setting up a git repository to help aid collaboration on the port of restful_authentication to merb as merbful_authentication.

This is such a good library and I use it in all my rails sites that need authentication. It just works and I like that. All credit to Rick Olson for such a great plugin. Hopefully we'll be able to to a good job porting it.

Initially I setup a git repo with this. I'm starting to do most of my work in git so this is a good opportunity to keep going learning it.

You can get the WIP on this plugin via
git clone http://snatcht.com/git/merbful_authentication.git
# OR
git clone git://snatcht.com/git/merbful_authentication.git
This is really just a blank Merb app that has the beginnings of a port in it. There were so many people working on a port of this plugin I figured we might as well work on it together.

To include everyone in the development I needed to have svn as well. Rubyforge have been generous in approving a project for me.

The issue was, how to bring the svn into my local git repo so that I can push changes up to svn. Heres how I did it.
git clone git://snatcht.com/git/merbful_authentication.git

cd merbful_authentication.git

mate .git/config
In this file I put the following
[svn-remote "rubyforge/trunk"]
url = svn+ssh://username@rubyforge.org/var/svn/merbful-auth/trunk
fetch = :refs/remotes/rubyforge/trunk
Then to get the SVN linked into my local git
git-svn fetch rubyforge/trunk

git branch -a
* master
origin/HEAD
origin/master
rubyforge/trunk
You can see that rubyforge/trunk is now present in my git remote branches. Next create a branch from rubyforge/trunk
git checkout -b local-svn/trunk rubyforge/trunk
This will create a local branch that you can use in git like any other branch. Now once you've made changes to your app. Merge them into the local-svn/trunk then update your svn repo with a lazy
git-svn dcommit
from within the local-svn/trunk branch.