Monday, February 04, 2008
« No PhotoShop Required | Main | Short Term Memory »

...or two.

I've had two projects this week where their/my bacon was saved by the branching strategy used for the source code repository. In my line of work, I touch a wide variety of projects. Some are still shiny new and others were written years ago; they're all in a source control repository.

Modern source control repositories (and by modern, I mean things that are not your file server or P:\ drive) let you create a branch. Branching might appear complex at first, but it's really pretty simple - at least conceptually. Here's a little story to illustrate the point of branches.

When I create a branch, I have a snapshot of the code at a particular point in time. So, imagine that on Monday, I have a single branch called the "trunk". It contains all of the code for my web site. On Tuesday, I created a branch based on the code in the trunk. I named my branch "BR-1". When I created BR-1, it was a mirror image of the trunk. I edited the code in BR-1 for a couple of days and nearly got it how I wanted it. My edits were isolated to BR-1 and they did not exist in the trunk.

I got a call early on Friday morning about an important change that needed to go out right away. I couldn't implement the urgent change to BR-1 because it contained my partially completed work. It was a pretty small change; a few hours of brilliant coding and I would be ready for a peer review of my changes. So, I checked out the trunk and made the edit right there and checked it back in. I published the urgent change I made on the trunk out to the live web site in the early afternoon and went back to working on BR-1.

By mid-day on the following Monday, I had finished all of my changes to the BR-1 branch. I had merged the BR-1 code into the trunk too. Now my trunk code contained the changes from BR-1 as well as that urgent change that came through on Friday morning. Complete control with the flick of a switch.

In the previous story, I was able to handle the urgent request efficiently because I used branching to manage my code changes. If I didn't have branching available as a software development tool, I would have some bad choices to make. Either I merge the urgent fix with my own enhancements and risk problems by rushing it, or force the urgent change to wait until my own changes were done; neither are necessary.

Branching is great way to ensure that I can always put my work on the shelf in lieu of more pressing matters. Understanding the concepts of branching is essential to being a valuable member of the team. The keys you actually press to make a branch or merge two branches can be left up to the nerdy folk. For more info, check out Pragmatic Version Control Using Subversion.