読み物Git · Collaboration

Level: Intermediate

Git Branching Strategies: Trunk-Based Development, Git Flow, and Feature Branches

How long should branches live, and how should work reach a release? Trunk-based development, feature branches, Git Flow, and release branches compared honestly.

Edeeson Opina7 min read

An Intermediate lesson card: lesson 8 of the Git & Version Control series, Git Branching Strategies: Trunk-Based Development, Git Flow, and Feature Branches, with the Miso fox walking.

What you’ll learn

  • Explain why branch lifetime drives integration risk
  • Describe trunk-based development and feature flags
  • Compare GitHub Flow, Git Flow, release branches, and environment branches
  • Choose and document a strategy for a given team
On this page
  1. Before you start
  2. What a strategy decides
  3. Trunk-based development
  4. Feature branches with pull requests (GitHub Flow)
  5. Git Flow
  6. Release branches and environment branches
  7. Choosing a strategy
  8. Signs your strategy isn't working
  9. Common mistakes and troubleshooting
  10. Practical exercise: compare two strategies
  11. Key takeaways
  12. References
  13. What's next

Git lets you create as many branches as you like, which raises a practical question every team has to answer: which branches exist, how long do they live, and how does work flow from a developer's laptop to a release? The answer is a branching strategy. This lesson compares the main ones (trunk-based development, feature branches with pull requests, Git Flow, and release or environment branches), explains the trade-offs honestly, and helps you choose one for a solo project, a startup, a larger team, or a library that supports several versions.

Before you start

You should know branching, merging, and pull requests from the earlier lessons, especially Pull Requests, Merge Requests, Code Reviews, and Team Collaboration.

What a strategy decides

Every branching strategy answers the same questions:

  • Where is the integrated, current code? Usually one main branch.
  • How long do branches live? Hours, days, or months.
  • How do changes get there? Direct commits, reviewed pull requests, or merges between long-lived branches.
  • How are releases made? From main, from a release branch, or from a tag.
  • How are fixes delivered to versions already released?

The single most important variable is how long work stays separate before it's integrated. Long-lived branches feel safe, because nobody else's changes interfere, but the longer two lines of work diverge, the bigger and riskier the eventual merge. Integration problems don't disappear; they're postponed and grow.

Trunk-based development

In trunk-based development, everyone integrates into one branch, the trunk (usually main), at least daily. Branches, if used at all, are tiny and live for hours or a day or two, merged through a quick review.

Unfinished features are merged too, hidden behind feature flags, so main is always releasable:

feature-flags.tsTypeScript
// A minimal flag check. Real projects often use a flag service with per-user targeting.
const flags = { newCheckout: process.env.FLAG_NEW_CHECKOUT === "on" };

export function checkoutPage(cart: Cart) {
  return flags.newCheckout ? renderNewCheckout(cart) : renderCheckout(cart);
}

Trunk-based development depends on discipline and tooling: fast automated tests on every change, small commits, and a habit of removing flags once a feature is fully released. The DORA research program, which studies software delivery performance, has repeatedly found trunk-based development to be associated with better delivery outcomes, which is why it's widely recommended for teams that deploy continuously. Association isn't a guarantee, and the practices around it (automated testing, small batches) matter as much as the branching itself.

Fits: teams that deploy often and have good automated tests. Watch out for: feature flags that are never removed, and pushing untested work to main.

Feature branches with pull requests (GitHub Flow)

The most common strategy on hosting platforms, often called GitHub Flow, is a variant of trunk-based development with review built in:

  1. main is always deployable.
  2. Each change gets a short-lived branch from main.
  3. A pull request is opened, reviewed, and checked by CI.
  4. It's merged into main, and main is deployed.

The key word is short-lived. A feature branch that lives for two days is close to trunk-based development; one that lives for two months is a long-lived branch with all its problems. Keep branches small by splitting work into steps that each leave main working.

Fits: most teams, including small ones and open-source projects. Watch out for: branches that grow for weeks; slow reviews that encourage bigger branches.

On busy repositories, several pull requests can each pass CI on their own and still break main when combined. A merge queue (available on GitHub and GitLab, among others) fixes this: approved changes wait in line, and each is tested together with the ones ahead of it before it's merged.

Git Flow

Git Flow, described by Vincent Driessen in 2010, uses several long-lived and supporting branches:

  • main (originally master): only released versions, each tagged.
  • develop: the integration branch for the next release.
  • feature/*: branched from and merged back into develop.
  • release/*: branched from develop to stabilize a release, then merged into main and back into develop.
  • hotfix/*: branched from main to fix production, then merged into both main and develop.

Git Flow brings structure to software released in discrete, scheduled versions, where several versions must be prepared and stabilized. It also adds overhead: more branches, more merges, and more chances for a fix to land in one branch and be forgotten in another. Its author added a note in 2020 suggesting that teams practicing continuous delivery, such as most web applications, adopt a simpler workflow like GitHub Flow instead.

Fits: products shipped as versioned releases on a schedule. Watch out for: using it for a continuously deployed web app, where it mostly adds ceremony.

Release branches and environment branches

Two narrower patterns combine with the strategies above.

Release branches support versions after they ship. A library might keep release/2.x and release/3.x alive to deliver security fixes to users who can't upgrade yet. The rule that keeps this sane: fix on main first, then cherry-pick the fix into each supported release branch (lesson 10), so no fix exists only in an old version.

Environment branches (for example develop, staging, and production, a pattern associated with GitLab Flow) represent what's deployed where. Changes flow in one direction, from the main branch toward production, and a merge into an environment branch triggers its deployment. This makes deployments visible in Git history and lets a team require approvals before production. The risk is drift: if someone fixes something directly on production, the branches diverge. Always flow changes forward, never backward.

Choosing a strategy

There's no universally best strategy, only one that fits how you release:

  • Solo developer or small project: work on main with short branches for anything risky. Add pull requests if you want CI to check changes before they land.
  • Startup or product team deploying continuously: feature branches with pull requests, kept to a day or two, plus feature flags for larger features. Aim for trunk-based habits.
  • Larger organization with compliance needs: the same, plus protected branches, required reviews, and possibly environment branches or a merge queue to make deployments auditable.
  • Library or app with supported versions: main plus release branches for each supported major version, with fixes cherry-picked from main.
  • Scheduled, versioned product releases: Git Flow or a lighter variant (main plus release branches) can fit, as long as you keep feature branches short.

Whatever you choose, write it down in the repository (for example in CONTRIBUTING.md): branch names, how changes get reviewed, how releases are made, and how hotfixes flow. A strategy only works when everyone follows the same one.

Signs your strategy isn't working

  • Merges regularly take hours and produce many conflicts.
  • People ask "is this fix in the release?" and nobody knows without checking several branches.
  • Branches stay open for weeks waiting for review.
  • Main is often broken, so nobody trusts it.
  • Hotfixes are made on one branch and rediscovered as bugs later because they never reached main.

Each of these points to the same remedies: smaller changes, faster review, better automated tests, and a clearer one-way flow of changes.

Common mistakes and troubleshooting

  • Adopting Git Flow by default. It's designed for scheduled releases; continuous deployment usually needs less.
  • Long-lived feature branches. Integrate at least daily, or merge main into the branch often.
  • Fixing in a release branch only. Fix on main first, then cherry-pick to release branches.
  • Changes flowing backward between environment branches. Always promote forward; never edit production directly.
  • Feature flags that live forever. Track them and remove them after release.
  • An unwritten strategy. Document it, and enforce key rules with branch protection.

Practical exercise: compare two strategies

  1. In a practice repository, simulate a week of work with GitHub Flow: create five short branches, each with one or two commits, merged into main through pull requests (or local merges). View the result with git log --oneline --graph --all.
  2. In a second repository, simulate the same work with Git Flow: develop, two feature branches, a release branch, and a hotfix merged into both main and develop.
  3. Compare the two graphs. Count the merges each needed and note where a fix could have been missed.
  4. Write a half-page CONTRIBUTING.md section describing the strategy you'd choose for one of your own projects, and why.

Key takeaways

  • A branching strategy decides how long work stays separate, how it's integrated, and how releases and fixes flow.
  • The longer branches live, the bigger and riskier integration becomes.
  • Trunk-based development and short-lived feature branches with pull requests fit continuous delivery; feature flags hide unfinished work.
  • Git Flow fits scheduled, versioned releases; its author recommends simpler workflows for continuous delivery.
  • Use release branches for supported versions, fix on main first, and document whichever strategy you choose.

References

What's next

Mistakes happen in every strategy. Undoing Mistakes in Git: Restore, Reset, Revert, and Reflog shows how to recover safely, and which commands can destroy work.

See every lesson in Git & Version Control: From Fundamentals to Advanced Workflows