Using Trunk Based Development
Trunk-based development is a software development practice where all developers commit code directly to a single branch—typically called "main" or "trunk"—instead of working on long-lived feature branches. This approach encourages small, frequent commits, continuous integration, and tight collaboration among team members. The goal is to reduce merge conflicts, improve code quality, and accelerate the release process by always keeping the trunk in a deployable state.
🧭 1. Embrace the Mindset
- The trunk is your
main
ormaster
branch. It's always deployable. - Avoid long-lived branches—use either direct commits to trunk or very short-lived feature/task branches that merge back quickly.
🛠️ 2. Keep History Simple
- Your Git history is a timeline of commits and pointers (branches/tags).
- Regularly run
git fetch
andgit rebase origin/main
(orgit pull --rebase
) to stay up-to-date before pushing.
🔁 3. Day-to-Day Workflow
- Work in small increments—either on trunk or a short-lived branch.
- Use feature toggles or abstractions to hide incomplete work if needed.
- Test locally, then rebase onto the latest trunk and resolve conflicts.
- Push and open a PR or merge directly.
- CI runs tests to keep the trunk green and healthy.
- Optionally tag and release versioned artifacts (e.g.,
v0.0.1
).
Fetch upstream changes
git fetch
git rebase origin/main
🚀 4. Automate & Protect
- Automate CI/CD pipelines to build, test, and deploy each commit.
- The trunk should always be deployable—fix any failing build immediately.
- Use feature toggles to safely integrate incomplete work and remove toggles when done.
✅ 5. Benefits in a Nutshell
- Fewer merge conflicts thanks to smaller, frequent merges.
- Continuous integration enables rapid deployment.
- Greater visibility and stability: everyone works off the same, up-to-date branch.
🚧 6. Watch-Outs & Best Practices
- Requires strong discipline: small commits, reliable testing, and clear processes.
- Clean up feature flags after features are complete to avoid clutter.
- Maintain strong team communication, since trunk changes frequently.
🔁 Summary Table
Principle | Practice |
---|---|
🛤️ One Trunk | Always commit to main/master , no long-lived branches |
🔄 Frequent Integration | Merge or rebase daily or multiple times a day |
🎛️ Hiding Incomplete Work | Use feature flags or abstraction layers |
🤖 CI/CD | Automate build, test, deploy on every trunk commit |
🧹 Clean Up Toggles | Remove feature flags once features are stable |
🛡️ Trunk Protection | Fix failing trunk immediately to keep it deployable |
✅ Final Notes
Trunk-based development promotes fast feedback, reduced complexity, and a collaborative engineering culture. Start with daily rebases and short-lived branches, adopt feature flags, and enforce CI/CD to keep your trunk clean and shippable.