Branching strategies

Git · Advanced · 12 min

A shared branching convention decides how painful merges, releases and hotfixes are for the whole team.

Git doesn't impose a workflow; teams agree on one. The main families:

Trunk-based development: everyone integrates into main (the trunk) at least daily, via very short-lived branches or directly. Unfinished features hide behind feature flags rather than living on long branches. It needs good automated tests and CI, and it minimizes merge pain because nothing diverges for long. It is the norm for teams practising continuous delivery.

GitHub flow: main is always deployable; every change is a branch plus pull request; after review and green CI it merges and deploys. Essentially trunk-based with PRs. A good default for web services and most teams.

Git flow: long-lived develop and main branches, plus feature/*, release/* and hotfix/* branches with prescribed merges between them. It suits software that ships numbered versions on a schedule and must support several in parallel, but it adds ceremony and long-lived divergence. Its own author has noted it is overkill for continuously delivered web apps.

Release branches combine with any of these: cut release/2.4 from main at release time, stabilise and patch it (cherry-picking fixes from main), and tag versions on it.

How to choose:

  • Deploy continuously? Trunk-based or GitHub flow.
  • Maintain multiple shipped versions (mobile apps, libraries, on-prem)? Add release branches, or Git flow.
  • Whatever you choose, keep branches short-lived, protect main (required reviews and checks), and pick one PR merge style.

The strongest predictor of merge pain is branch lifetime, not the strategy's name.

Remember

  • Trunk-based: integrate daily, hide unfinished work behind feature flags
  • GitHub flow: main always deployable, branch + PR + deploy
  • Git flow and release branches suit versioned, multi-version products
  • Short-lived branches matter more than the strategy's name

Watch out for

  • Adopting Git flow for a continuously deployed web app and living with permanent develop/main drift.

Check yourself

  1. A team deploys a web service many times a day. Which approach usually fits best?
  2. What lets trunk-based teams merge unfinished features safely?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows

Builds on

Unlocks

Nothing builds on this yet.