Git Branching Strategies: GitFlow vs Trunk-Based Development

Why Branching Strategy Matters

A branching strategy is a team agreement about how code flows from a developer's machine to production. Bad strategies cause: merge conflicts that take longer to resolve than the feature took to build, broken main branches, and deployments that bundle unrelated changes.

---

GitFlow

GitFlow uses two permanent branches (main and develop) and several types of short-lived branches.

main ──────────────────────────────────────── (released versions)
        ↑                          ↑
develop ──────────────────────────────────── (integration branch)
           ↑              ↑
feature/login          feature/search

Branch types:

When GitFlow makes sense:

When it does not make sense:

---

Trunk-Based Development

All developers commit to main (the "trunk") either directly or via very short-lived feature branches (less than 2 days).

main ─────────────────────────────────────── (always releasable)
         ↑  ↑  ↑       ↑       ↑
short-lived feature branches (1-2 days max)

How it handles incomplete features: feature flags. Code ships to production but is hidden behind a flag until ready.

When it makes sense:

Requirements: good test coverage (you cannot merge to main without it), feature flags for incomplete work, team discipline to keep branches short.

---

GitHub Flow

A simplified version of GitFlow without develop or release branches:

main ──────────────────────────────
        ↑            ↑
feature/login   feature/search
  (PR → review → merge → deploy)
  1. Branch from main
  2. Make changes, push, open a pull request
  3. Review, merge to main
  4. Deploy immediately

When it makes sense: web applications, SaaS products, teams deploying continuously. Simpler than GitFlow, less disciplined than trunk-based.

---

Choosing a Strategy

FactorTrunk-BasedGitHub FlowGitFlow
Deploy frequencyMultiple/dayMultiple/weekScheduled releases
Team sizeAnySmall-mediumMedium-large
Test coverage neededHighMediumMedium
Feature flagsYesOptionalNo
Release managementSimpleSimpleComplex

---

Practical Transition: GitFlow → GitHub Flow

The most common transition for growing teams:

  1. Stop creating release/* branches — deploy directly from main
  2. Merge features to main via PRs (same as before)
  3. Delete develop after all teams are using main as the integration point
  4. Add CI/CD to gate merges on passing tests

Practice branching in the ShellGenius Git Labs — the git-branch-merge and git-undo-changes challenges use real branching scenarios.