How to implement trunk-based development

· Category: Git

Short answer

Trunk-based development emphasizes a single main branch, short-lived branches or direct commits, and feature flags for incomplete work.

Steps

  1. Keep main as the only long-lived branch.
  2. Create short-lived feature branches (hours to a day):
git checkout -b feature/toggle
  1. Merge quickly via pull requests:
git push origin feature/toggle
  1. Use feature flags to hide unfinished features in production.

Tips

  • Require automated tests and code review before merging.
  • Pair programming reduces the need for long review cycles.
  • Small, frequent commits reduce merge conflict risk.

Common issues

  • Long-lived branches contradict trunk-based principles and cause integration pain.
  • Insufficient testing can lead to a broken main branch.