Trunk-Based Development with Modern CI/CD
Ship faster with short-lived branches, feature flags, and continuous integration on the main trunk.
Long-lived feature branches create merge hell and delayed integration. Trunk-based development keeps main (or trunk) always releasable with small, frequent commits.
Trunk vs GitFlow
Daily CI/CD Loop
Feature flags
Incomplete features merge behind flags. Trunk stays deployable without exposing unfinished work to users.
Branch Policy
| Rule | Guideline |
|---|---|
| Branch lifetime | < 2 days |
| PR size | Small, reviewable diffs |
| Main branch | Always green CI |
| Releases | Tag trunk, not long release branches |
GitLab CI for Trunk
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
stages:
- validate
- test
- deploy
deploy:staging:
stage: deploy
script:
- ./deploy.sh staging
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy:production:
stage: deploy
when: manual
script:
- ./deploy.sh production
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHEnabling Practices
- Comprehensive automated tests — trunk must stay trustworthy
- Feature flags — LaunchDarkly, Unleash, or env-based toggles
- Pair programming / fast reviews — unblock small PRs quickly
- Branch protection — require CI pass before merge
Metrics to Track
- Integration frequency — merges per day
- Lead time — commit to production
- CI duration — keep under 10 minutes for fast feedback
- Change failure rate — should decrease with smaller batches
Conclusion
Trunk-based development works when CI is fast and feature flags decouple deployment from release. Start by shortening branch lifetime before reorganizing your entire Git model.
Related Articles
Docker Multi-Stage Builds in CI/CD Pipelines
Shrink images, speed up pipelines, and improve security with multi-stage Dockerfiles in GitLab CI.
Vercel + GitLab: CI/CD for Next.js Portfolios
Combine GitLab for source control and optional CI checks with Vercel for zero-config Next.js deployment.
GitLab CI to Kubernetes: End-to-End Deploy Pipeline
Design a complete CI/CD pipeline from GitLab merge request to Kubernetes production with security gates and GitOps handoff.