No history yet

Modern Branching Strategies

Beyond Basic Branching

Once you're comfortable creating branches and merging changes, the next step is to think strategically. On a professional team, branching isn't random; it follows a deliberate pattern, a shared agreement on how code moves from an idea to production. This is called a branching strategy.

These strategies shape how quickly teams can build, test, and release software. While many models exist, two dominant philosophies have emerged: GitFlow, a structured and traditional approach, and Trunk-Based Development, a faster, more modern workflow designed for continuous integration.

A branching strategy is a set of rules or guidelines that development teams use to manage the process of writing, merging, and deploying code with the help of a version control system like Git.

Two Competing Philosophies

GitFlow was created for a world of scheduled, versioned releases. Think of software that gets a big update every few months. It's built around multiple long-lived branches, each with a specific purpose, creating a highly structured but complex process.

This model provides clear separation between new development, release preparation, and emergency fixes. However, its feature branches can live for weeks or even months. The longer a branch exists, the more it diverges from the main codebase, leading to painful, complex merges—often called "merge hell."

Trunk-Based Development (TBD) offers a radical simplification. The vast majority of work happens on a single branch, called the "trunk" (commonly named main). Developers create very short-lived branches for a single task, integrate their changes back into the trunk within a day or two, and then delete the branch.

This relentless pace of integration is the heart of Continuous Integration (CI). Because changes are small and frequent, merge conflicts are rare and simple to fix. The primary goal is to keep the trunk in a healthy, releasable state at all times.

How to Keep the Trunk Stable

Merging incomplete code to main sounds dangerous. How can the trunk always be releasable if it contains half-finished features? The solution isn't to delay merges, but to hide the work-in-progress from users. This is done with feature flags.

Feature Flag

noun

A mechanism that allows parts of a program to be turned on or off at runtime, without deploying new code.

A feature flag (or feature toggle) is essentially an if statement in your code that checks whether a feature should be active.

if (featureFlags.isNewDashboardEnabled()) {
  // Show the new, work-in-progress dashboard
} else {
  // Show the old, stable dashboard
}

With this approach, code for the new dashboard can be safely merged into the main branch piece by piece. The feature is deployed but not released. Once the feature is complete and tested, the flag can be flipped on for everyone, instantly releasing the new functionality without a new deployment. This decouples deployment from release, a core principle of modern DevOps.

While TBD is ideal for web applications that are deployed continuously, some products still need versioned releases, like mobile apps or enterprise software. For this, a hybrid model works well: the Short-Lived Release Branch.

The team follows TBD on the main branch. When it's time to prepare a new version (e.g., V2.1), a release/2.1 branch is created from main. From this point on, only critical bug fixes are added to the release branch. All new feature development continues on main. This allows the release to be stabilized and tested in isolation while the trunk moves forward at full speed. Once the release is shipped, the branch is deleted.

The End Goal

The philosophy behind Trunk-Based Development and feature flags is to keep main always releasable. This doesn't mean every commit is deployed to production, but that it could be. Every merge to the trunk must pass a full suite of automated tests, ensuring it hasn't broken anything.

This discipline reduces risk. Instead of one massive, high-stakes merge before a release, you have hundreds of tiny, low-risk merges. It makes development faster, more predictable, and less stressful. By choosing a branching strategy that minimizes the lifetime of branches, teams can spend less time untangling code and more time building.

Quiz Questions 1/5

What is the primary purpose of adopting a branching strategy in a software development team?

Quiz Questions 2/5

Which statement best describes a key difference between GitFlow and Trunk-Based Development (TBD)?

Modern branching strategies are all about finding a balance between speed and stability that fits the needs of your team and product.