Branching: Friend or Foe?

Consider the following diagram, which is attempting to show features being added to program in a source control system.

BranchesFirst feature B is added to the mainline A, as feature B is a fairly large change and leaves the programmer with two choices (explanation of terms)

  1. They can add B to the mainline to create AB, this is nothing special and I’m not going to write any more about it.
  2. They can branch the mainline and add B to the branch (C) which then contains AB.

At first glance nothing earth shaking has taken place as adding B to the mainline or to the branch would produce the same thing: AB (I’ve labeled the branch C version to prevent confusion).  If the branch C is then immediately merged (integrated) back into the mainline to create AB in the mainline, then this is quite a sound way to add a major feature that require lots of changes to the mainline.

However things can rapidly become more complicated when branching if additional independent changes are made to either the mainline or the branch.  Consider what would happen if feature D is added to the branch to produce CD (ABD) and feature E is added to the mainline to produce ABE. Integrating the branch back into the mainline (to produce ABED) just became very much harder: especially if either or both of the new features changed a lot of files, as this increases the chances of changes occurring in the same file to the same piece of code in changes D and E.  This integration task would also become much harder and more time consuming if the branch had not been integrated back into the mainline after B was added.

Branching is not bad, it is a powerful and effective tool but it does require discpline to integrate often and the time investment to frequently perform the nessessary integrations to keep the branch(s) syncronised with the mainline.  The main risk with branching is that frequent integrations will not be performed and at some point integration will become practically impossible: as the branch and mainline will have so many independent changes that attempting to merge them back together could only be achieved with a truly hurculian effort and a corresponding collossal investment of time.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>