Contributing to Rails with Git

January 17, 2008 – 11:09 am

I’ve been experimenting lately with git - a distributed version control system (DVCS) that’s been gaining popularity over the last few months. Git’s got a couple of fantastic features, but for me - coming from SVN - there were a few stumbling blocks. Despite the wealth of documentation and tutorials on the web, though, I was unable to find exactly what I needed online, so I thought I’d record it here so that others don’t have to search so much.

Setup

I used this post as a guide to installing git on my local machine. Unfortunately, I wasn’t smart about it - as it happens, the code there gives you an older release of the software that made my life harder in the long run. If you want to avoid those issues, try this instead:

curl http://kernel.org/pub/software/scm/git/git-1.5.3.8.tar.gz -O
gunzip git-1.5.3.8.tar.gz ; tar -xvf git-1.5.3.8.tar; cd git-1.5.3.8
make configure
./configure --prefix=/usr/local
make all
sudo make install

After that, proceed as the original post recommends (setting your PATH and the name and email defaults).

As for gitifying my Edge installation… that was easy. I just used the examples from this post, and I was set.

Contributing

Previously, I had an edge_rails folder that I checked out http://dev.rubyonrails.com/svn/rails/trunk to. When I wanted to patch Rails, I’d svn up to ensure I had the latest codebase, make my changes there. When I was satisifed, I’d then run svn diff > ../patches/appropriately_named.patch and submit that to Trac as a new ticket.

With git, the process is a little different. First, I create a new branch for the functionality I want to work on. For instance, when I’m working on grouping by multiple fields in ActiveRecord::Calculations (this patch - comments and +1s welcome!), I might do git checkout -b multiple_field_group master, which will create a new branch with the contents of master (which is Edge) and switch to it.

At this point, I can do whatever I need to - committing as I go, since my repository is stored locally - until I’m happy. Once I’m done, I can generate the patch with git diff -p master > ../patches/appropriately_named.patch; the -p option makes it a unified diff, just like svn diff produces. The core team has gone on record (in #rails-contrib, if nowhere else) as saying that they’re fine with git patches created in this way, so from there it’s just the same as before - upload to Trac and wait for the +1s to roll in.

Who cares?

There are a couple of big benefits to using git in this manner. First, I can develop complex patches much more easily by committing to my local branch as I go. Also, I can have multiple patches in the queue all at once, each living in its own branch. This means that I can keep patches up-to-date as Edge is updated more easily, too.

All in all, using git to manage my contributions to Rails is a huge win - and I’m evangelizing it to anyone who’ll listen. Go forth and gitify your Edge!

  1. One Response to “Contributing to Rails with Git”

  2. Thanks for the great post - I just submitted my first patch using this format.

    I wrote up how I manage all of the peripherals on my own machine as well at:

    http://zilkey.com/2008/5/1/adding-patches-to-rails-now-that-it-s-on-git

    By Jeff Dean on May 1, 2008

Post a Comment