How to Manage Long-Running Feature Work With Flags
Feature flags let you merge incomplete work to main safely, replacing long-lived branches so integration and CI stay continuous.
Long-running features do not need a long-lived branch. Merge the code to main behind a flag that keeps it off in production. CI tests both flag states, and you flip the flag when the feature is ready. This is the trunk-based answer to big features.
Steps
- Guard the new code path behind a flag that defaults off.
- Merge small increments to main behind the flag.
- Test both flag states in CI with a matrix.
- Flip the flag on when the feature is complete, then remove it.
Test both flag states
.github/workflows/ci.yml
jobs:
test:
strategy:
matrix:
flag: ['off', 'on']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
env:
FEATURE_NEW_CHECKOUT: ${{ matrix.flag }}Gotchas
- Stale flags accumulate; schedule their removal once the feature is fully rolled out.
- Untested off-by-default paths rot; keep both states in CI until you remove the flag.
Related guides
How to Set Up CI for Trunk-Based DevelopmentWire CI for trunk-based development where everyone commits to main behind short-lived branches, running the f…
How to Choose Between Short-Lived and Long-Lived BranchesCompare short-lived and long-lived branches for CI cost and merge risk, and set up integration so branches st…
How to Choose Which Branching Strategy to UseChoose between trunk-based, GitHub Flow, GitFlow, and GitLab Flow based on release cadence, environment count…