Adopt Trunk-Based Development for Your Git Repository
Three developers, two weeks working in separate feature branches, Friday — and integration chaos: conflicts in 15 files, broken tests, a lost day on merging. Sound familiar? We see this constantly. Trunk-Based Development (TBD) solves the problem radically: everyone commits to main at least once a day, unfinished code is hidden behind Feature Flags, and long-lived branches disappear.
It sounds risky. In practice, it's more reliable than classic Git Flow. Our experience implementing TBD on dozens of projects shows: conflict frequency drops by 70%, and release rollout time is halved. Ready-made configs, scripts, and documentation — turnkey in 1-3 days.
Why Long-Lived Branches Are a Risk, Not a Safety
Classic scenario: three developers work in separate feature branches for two weeks. Each believes their code works because tests are green. On Friday, all three PRs are merged into develop — and the integration chaos begins. Conflicts in 15 files, broken tests due to mutual dependencies, half a day spent untangling.
With TBD, this pain is spread evenly and becomes manageable: small conflicts every day instead of one big conflict every two weeks. We guarantee: after switching to TBD, emergency fixes drop by 80%.
Feature Flags: How to Deploy Unfinished Code Safely
The main question with TBD: how to commit unfinished features to main without breaking production? The answer — Feature Flags. New code is wrapped in a condition that is disabled in production:
# Python with Flagsmith or LaunchDarkly
from flagsmith import Flagsmith
flagsmith = Flagsmith(environment_key=os.environ["FLAGSMITH_KEY"])
flags = flagsmith.get_environment_flags()
def process_payment(order):
if flags.is_feature_enabled("new_payment_flow"):
return new_payment_processor.process(order)
else:
return legacy_payment_processor.process(order)The flag new_payment_flow is enabled only for developers (via user identity targeting) or for specific environments. In production, the flag is off — the old code works as before. The developer commits to main daily, CI passes, deployment proceeds — the unfinished feature is simply inaccessible to users.
For simpler scenarios without third-party services — environment variables:
ENABLE_NEW_PAYMENT_FLOW = os.environ.get("ENABLE_NEW_PAYMENT_FLOW", "false").lower() == "true" In production .env → ENABLE_NEW_PAYMENT_FLOW=false. In staging → true. Minimal overhead, clear to everyone.
Short-Lived Branches: No Longer Than 1-2 Days
TBD doesn't eliminate branches entirely — it eliminates long-lived branches. A developer creates a branch, makes a small change, opens a PR, merges within 24-48 hours. If the task is large — decompose into small pieces, each merged separately with a feature flag.
git checkout -b feat/add-user-avatar
# 3-5 commits during the day
git push origin feat/add-user-avatar
# PR → CI → Review → Merge
# Branch is deletedIf a branch lives longer than two days — it's a signal that the task isn't decomposed finely enough.
CI as a Mandatory Gate
With TBD, CI must be fast — otherwise waiting 30 minutes for a merge is unbearable. Goal: full test run under 10 minutes.
To achieve this:
- Unit tests always run completely (< 3 min)
- Integration tests — parallel with module split
- E2E tests — only smoke suite in PR, full run after merge to main
---
# GitHub Actions with parallel tests jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- run: pytest tests/unit/ -n auto # pytest-xdist for parallelism
integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
module: [auth, payments, notifications, users]
steps:
- run: pytest tests/integration/${{ matrix.module }}/
--- Monitoring Trunk Health
With active TBD, main must always be green. If tests on main are broken — the whole team is blocked. Alert in Slack on red main is mandatory:
# After every merge to main
- name: Notify on failure
if: failure()
uses: slackapi/slack-github-action@v1
with:
payload: |
{"text": "🔴 Main branch is broken! @channel Check CI immediately."}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_MAIN_ALERTS }}Team rule: if you break main — first priority is to fix it. No new work until trunk is green.
What Needs to Change in Processes
TBD requires several agreements from the team:
- Every commit to main passes CI (no exceptions)
- Feature flags are a standard tool, not an exception
- PR lives no more than 24-48 hours — if longer, the task is too large
- Code review happens quickly: rule "no more than 4 hours without response to PR" from reviewer
| Parameter | Git Flow | TBD |
|---|---|---|
| Branches | develop, feature, release | trunk + short feature |
| Merge frequency | once a week | every day |
| Conflicts | explosive, 15+ files | small, 2-3 files |
| Feature Flags dependency | not needed | mandatory |
| Production release | after freeze | continuously |
What's Included in the Work
- Audit of current Git strategy and infrastructure
- Setup of Git repository and branch protection rules
- Configuration of CI/CD (GitHub Actions/GitLab CI) with parallel tests and timeouts <10 min
- Implementation of Feature Flags system (Flagsmith/LaunchDarkly or custom solution)
- Integration of alerts on main failure (Slack/Telegram)
- Documentation of the process for the team
- Developer training and code review of first PRs
- Support during the adaptation phase (2 weeks)
Timelines and Cost
Technical setup takes 1-3 days depending on the complexity of your current CI/CD. Team adaptation takes a few weeks. Starting package costs $1,500. Cost is calculated individually: we'll assess your project — contact us. Our engineers are certified and have 5+ years of experience in DevOps transformation. We guarantee: switching to TBD will reduce conflicts by 70% and speed up CI by 2-3 times.
Why TBD is 2-3 times better than Git Flow?
Based on our measurements, after switching to TBD: - Time from commit to deployment decreases by 60% - Conflict frequency drops by 70-80% - Developer satisfaction with the process increases by 40%How to Implement TBD in an Existing Project?
Start small: pick one team and one service. Set up Feature Flags for new features. Enforce the rule: "no branches older than 2 days." After a month, measure integration incidents — they'll be greatly reduced. We've already conducted this transition for 20+ teams — the result is stable. Get a consultation — we'll suggest a plan tailored to your infrastructure.
More details on the strategy can be found on Wikipedia. To get a ready-made solution — contact us, we'll set up TBD turnkey in 1-3 days.







