Categories
Uncategorized

Software Branching and Parallel Universes

“Savage Chickens” comic: “What if your life is boring in all the parallel universes?”


Over at his blog Coding Horror, Jeff Atwood talks about what’s probably the trickiest part of version control: branching.
He quotes the Subversion docs’ layperson-friendly explanation of branching:

Suppose it’s your job to maintain a handbook for a particular division of your company. One day a different division asks you for the same handbook– but with a few parts modified specifically for them, as they do things slightly differently.

What do you do in this situation? You do the obvious thing: you make a second copy of your document, and begin maintaining the two copies separately. As each department asks you to make small changes, you incorporate them into one copy or the other. But you often find yourself wanting to make the same change to both copies. For example, if you discover a typo in the first copy, it’s very likely that the same typo exists in the second copy. The two documents are almost the same, after all; they only differ in small, specific ways.

This is the basic concept of a branch — a line of development that exists independently of another line, yet still shares a common history. A branch always begins life as a copy of something, and moves on from there, generating its own history.

If branching reminds you of parallel universes, you’re not alone. Parallel universes are a staple of science fiction and geek literature, from the Star Trek episode where Spock has a Fu Manchu-style beard to that oddball Gwyneth Paltrow movie to the out-of-continuity comics like Marvel’s What If… and DC’s Elseworlds series. Jeff finds “parallel universes” to be a handy analogy for explaining branching. (He also cites some comic book classics featuring parallel universes for geek bonus points.)

He lists a number of approaches to branching (or “branching patterns”, if you prefer), complete with diagrams. I’ve gathered the diagrams and placed them into a single graphic below — he describes each in a little more detail.

Diagrams of different branching patterns, by Jeff Atwood.

Branching is tricky, but if you’re not making use of it, you’re missing out on one of version control’s most important benefits. As Jeff puts it:

Still, I urge developers to make an effort to understand branching– really understand it– and explore using branching strategies where appropriate on their projects. Done right, the mental cost of the branching tax pales in comparison to the benefits of concurrent development it enables. Embrace the idea of parallel universes in your code, and you may find that you can get more done, with less risk. Just try to avoid a crisis on infinite codebases while you’re at it.

Cross-posted to the Tucows Developer Blog.