Task Branch

You need place work that facilitates the use of feedback mechanisms such as testing and Code Review to help you merge with confidence so that you can have consistently working code on the Main Line. This pattern describes a codeline structure that enables your team to work in parallel to deliver multiple changes to the Main Line quickly while preserving the integrity of the Main Line and maintaining focus. Basic Task Branch

Balancing Isolation and Collaboration

A typical development workflow includes the following steps:

It’s typical to code and test in your private workspace before sharing your changes with the rest of the team. Unless you work in a communal workspace (which would be challenging), there is always a period of time when your changes are isolated from the Main Line. While this means that your work isn’t always up to date, having no isolation can become chaotic as the number of contributors increases.

A workspace, with or without a local branch, is a parallel work stream, much like a shared branch, but without the transparency and automation support branching enables.

![](taskBranch-workspace-branch.png height=“1.5 in”)

There are a few options for managing this isolated work stream. Each option differs in:

A good solution will allow you to work in a way that yields the benefits of (brief) isolation while minimizing the time until the code is merged into the Main Line.

Some of the ways you can manage the code in your workspace before integrating with the Main Line are:

A good solution will allow you to work in a way that yields the benefits of (brief) isolation while minimizing the time until the code is merged into the Main Line.

A workspace without a backing branch is straightforward to manage because it requires fewer interactions with the SCM tool. However, you cannot easily track steps during the coding process. Some of the disadvantages of this approach are:

A workspace with a local branch lets you track changes locally and experiment easily (see the Private Versions Pattern from SCM Patterns). However, this approach has the same issues regarding lack of transparency and tooling support workspace-only approach.

Using a branch, you can collaborate on a feature with other developers and get the advantage of quickly testing the code in the branch in a Continuous Integration Environment, opening up more potential for automation, information sharing, and collaboration without the right expectations. However, working on a branch can encourage slower, asynchronous interactions.

![Task Branch Forces](task-branch-context-forces.png height=“1.5 in”)

Using branches can cause problems when teams encourage working on a long-lived branch—such as a Feature Branch—until work is complete. While this seems to offer some superficial advantages, especially if the work is isolated from the rest of the code base, the cost of a longer gap between integration easily outweighs any potential advantage. The longer the delay, the higher the risk of merge conflicts and errors.

![](taskBranch-branchedBased-workflow.png height=“1.5 in”)

You want to enable collaboration and reliable testing while also working to minimize the length of time between starting work and merging, which includes:

Branch for Tasks, Merging Quickly

For each development task, work off a Task Branch. A Task Branch represents a small coherent unit of work that can be done reasonably quickly. Merge into the Main Line as quickly as possible

Task Branch Solution

A Task Branch starts from the Mainline. The branch ends when the task is merged. The meaning of “Merging quickly” can vary by team, but 1 day is a good target.

A Task Branch enables a developer to:

Using short-lived Task Branches is consistent with rapid integration to a Main Line. In Accelerate {Forsgren et al., 2018 #92987} the authors say:

Following our principle of working in small batches and building quality in, high- performing teams keep branches short-lived (less than one day’s work) and integrate them into trunk/master frequently.

A “Task,” which is described in more detail in Small Development Task can be a User Story {Cohn, 2004 #260909} or an intermediate step for a user story. The main attribute is that it is a small, coherent unit of work. Small can vary by team, but a typical goal is to be able to integrate at least daily.

Using a Task Branch model approach is mostly a matter of identifying units of work that can be completed quickly and building processes and styles that encourage quick collaboration and integration. If you are currently in the habit of using long-lived feature branches:

Example

A Task Branch follows a familiar workflow:

  1. Check out the Main Line
  2. Create a Task Branch
  3. Make code changes, including tests. This can include multiple commits
  4. Push changes to the shared repository periodically.
  5. Get feedback.
  6. Merge the completed work.
  7. Delete the Task Branch

The goal is to integrate the work into the _Main Line_quickly.

Cautions

Don’t confuse a Task Branch with a Feature Branch. A Task Branch is shorter and allows for incremental work. A Feature Branch often represents a larger unit of work that survives until the “feature” is complete, at which point the code merges to the Main Line. Feature branching is rarely a useful pattern to follow; use Task Branches for any work in progress.

Individuals and teams should minimize the number of active task branches {Forsgren et al., 2018 #92987}:

Our research also found that developing off trunk/master rather than on long-lived feature branches was correlated with higher delivery performance. Teams that did well had fewer than three active branches at any time, their branches had very short lifetimes (less than a day) before being merged into trunk and never had “code freeze” or stabilization periods.

Be mindful of:

Using a Task Branch can make these problems more obvious (since the SCM tooling makes the parallel work stream visible), but that doesn’t mean that the branching policy is the cause of the problem. These issues can also manifest when doing a no-branch directly from the workspace workflow. The causes of long integration times are often related to problems external to the code line flow, such as planning and prioritization.

Aside: Branch Reuse

One approach to balancing the overhead of branch creation with frequent integration is to create one branch for a larger task, but merge multiple times during the branch’s lifetime. If your policy if to delete the (remote) branch after a merge, this is conceptually the same as multiple task branches. The team should decide if there is any value to creating uniquely named branches for each merge. It’s conceptually simpler to think of each merge are coming from a new branch.

Next Steps

To integrate a task branch quickly while minimizing the risk of errors, you need to:

References