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
- Keep
mainas the only long-lived branch. - Create short-lived feature branches (hours to a day):
git checkout -b feature/toggle
- Merge quickly via pull requests:
git push origin feature/toggle
- 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
mainbranch.