When working with a SCM system, when should you branch?
You should branch whenever you cannot pursue and record two development efforts in one branch. (without having an horribly complicated history to maintain). A branch can be useful even if you are the only one working on the source code, or if you are many.
In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.
Generally create a branch for every feature you're working on. Commit all your changes there. Then when you're done, merge it (pull request or not) to wherever it needs to go.
Git branches are created in order to isolate specific Git commits from the rest of your main Git history. If you main Git history is based on the master branch, you can create a separate Git branch in order to develop new features and merge them later on.
In general term, the main purpose of branching (a VCS - Version Control System - feature) is to achieve code isolation.
You have at least one branch, which can be enough for sequential development, and is used for many tasks being recording (committed) on that same unique branch.
But that model shows quickly its limit:
When you have a development effort (refactoring, evolution, bug-fixes, ...) and you realize you cannot safely make those changes in the same branch than your current development branch (because you would break API, or introduce code that would break everything), then you need a another branch.
(To isolate that new code for the legacy one, even though the two code sets will be merge later on)
So that is your answer right there:
You should branch whenever you cannot pursue and record two development efforts in one branch.
(without having an horribly complicated history to maintain).
A branch can be useful even if you are the only one working on the source code, of if you are many.
But you should not make "one branch per developer":
the "isolation" purpose is made to isolate a development effort (a task which can be as general as "let's develop the next version of our software" or as specific as "let's fix bug 23"),
not to isolate a "resource".
(a branch called "VonC" means nothing to another developer: What if "VonC" leaves the project? What are you supposed to do with it?
a branch called "bugfix_212" can be interpreted in the context of a bug tracking system for instance, and any developer can use it with at least some idea about what he is supposed to do with it)
A branch is not a tag (SVN is a Revision System which tries to propose versioning features like branching and tagging through directories with cheap file copy: that does not mean a tag is a branch)
To define a branch means also defining a merge workflow: you need to know where to merge your branch when you are done with it.
For that, the chapter 7 of Practical Perforce (Laura WINGERD - O'Reilly) is a good introduction (VCS agnostic) to merge workflow between different kind of branches: " "How Software Evolves" (pdf)
It defines the term codeline (branch which records significant evolution steps of the code, either through tags at certain points, or through important merge back to the branch)
It introduce the mainline model (a central codeline to record releases), and describes various purposes for branching:
Other interesting concepts around VCS: Basics concepts
(about ClearCase originally, but also valid for any VCS)
There are several uses for branching. One of the most common uses is for separating projects that once had a common code base. This is very useful to experiment with your code, without affecting the main trunk.
In general, you would see two branch types:
Feature Branch: If a particular feature is disruptive enough that you don't want the entire development team to be affected in its early stages, you can create a branch on which to do this work.
Fixes Branch: While development continues on the main trunk, a fixes branch can be created to hold the fixes to the latest released version of the software.
You may be interested in checking out the following article, which explains the principles of branching, and when to use them:
All the 21th century SCMs are telling you:
Branch for every task you've to work on, no matter whether this is a new feature, a bugfix, a test, whatever. This is called topic branch, and it changes the way you work with your SCM.
You get:
Tools that can do it:
Tools that CAN'T do it:
It also depends on the SCM tool you are using. Modern SCMs (git, mercurial, etc.) make it increasingly easy to create and destroy branches whenever needed. This allows you to, for example, make one branch per bug that you are working on. Once you merge your results into the trunk, you discard the branch.
Other SCMs, for example subversion and CVS, have a much "heavier" branching paradigm. That means, a branch is considered appropriate only for something bigger than a twenty-something-line patch. There, branches are classically used to track entire development tracks, like a previous or future product version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With