Summary

Martin Fowler’s comprehensive reference (2020) on branching patterns, covering base patterns (source branching, mainline), integration patterns (feature branches, continuous integration, pull requests), and release patterns (release branches, release trains, environment branches). Overarching theme: integrate frequently, keep mainline healthy.

Martin Fowler 2020 年關於分支模式的全面參考,涵蓋基礎模式(源分支、主線)、集成模式(特性分支、持續集成、拉取請求)和發布模式(發布分支、發布列車、環境分支)。主題:頻繁集成,保持主線健康。

Key Points

  • Core tension: branching creates isolation for developers but merging is the tax you pay
  • Mainline (trunk): single shared branch that holds production-ready code; all integration happens here
  • Feature branches: short-lived branches for single features; key word: short-lived (days, not weeks)
  • Continuous integration: merging to mainline multiple times per day; requires feature flags for incomplete work
  • Integration frequency matters: long-lived feature branches accumulate divergence → painful merges; CI forces daily integration
  • Release branches: branch off mainline when preparing a release; only cherry-pick fixes back; keeps mainline clean for new development
  • Fowler’s recommendation: trunk-based development with feature flags > long-lived feature branches for high-performing teams

Insights

Fowler’s article is the canonical reference for why branching strategies matter operationally. The core insight — branches are cheap but merging is expensive — implies that branching strategies should be optimized for minimizing merge cost, not minimizing branch count. Long-lived feature branches don’t just delay integration; they accumulate technical risk that compounds. The CI practice (merge to mainline daily) is counter-intuitive for teams used to long feature branches but is validated by DORA research as a predictor of high-performing teams.

Connections

Raw Excerpt

The over-arching theme is that branches should be integrated frequently and efforts focused on a healthy mainline that can be deployed into production with minimal effort.