Trunk-Based Development (TBD) is a branching strategy where all developers commit to a single shared branch (main or trunk) multiple times per day. Feature flags control which features are visible to users. This approach enables true continuous integration.
Git
Beginner
9 min read
Trunk-Based Development
Example
# Trunk-Based Development principles:
# 1. Everyone commits to main (or very short-lived branches < 2 days).
# 2. CI runs on every commit — must stay green.
# 3. Use feature flags to hide incomplete features in production.
# 4. Small, incremental commits over large batches.
# Short-lived feature branch (merged same day or next):
git switch main && git pull
git switch -c feat/add-search-bar
# ... small focused changes ...
git add . && git commit -m "feat: add search bar UI component"
git push -u origin feat/add-search-bar
# Open PR -> quick review -> merge -> delete branch
# Feature flag pattern (simple example):
# config/features.js
# module.exports = {
# newDashboard: process.env.FF_NEW_DASHBOARD === 'true',
# betaCheckout: process.env.FF_BETA_CHECKOUT === 'true',
# };
# Usage in code:
# const flags = require('./config/features');
# if (flags.newDashboard) {
# return res.render('dashboard-v2');
# }
# return res.render('dashboard');
# When the feature is complete and rolled out:
# 1. Remove the feature flag check
# 2. Delete the flag from config
# 3. Clean up old code path
Related Resources
This is the last lesson in this section.
Create a free account to earn a certificate