Compares Git Flow and trunk-based development: branch types, release flow, merge pain, CI implications and why short-lived branches won.
Git Flow keeps two long-lived branches, main (released code) and develop (next release), plus feature/*, release/* and hotfix/* branches that merge back in a set order. Trunk-based development has one long-lived branch, main; developers branch for hours or a day or two, open a small pull request and merge behind CI checks, using feature flags to hide unfinished work.
Most teams moved to trunk-based because long-lived branches delay integration: the longer a branch lives, the bigger the merge and the later you find that two changes conflict. Short branches keep main always releasable, which is what continuous delivery needs.
The trade-off: trunk-based asks for good automated tests and flag discipline; Git Flow still suits products that ship numbered versions and patch several releases at once.
"Git Flow and trunk-based development are two answers to the same question: how long should code live away from everyone else's code? Git Flow says quite long. You have
main, which only holds released code, anddevelop, where the next release is assembled. Features live on their own branches until they're done, then merge intodevelop; when you're ready to ship you cut arelease/1.4branch, stabilise it, and merge it into bothmainanddevelop. Urgent fixes go onhotfixbranches that also merge both ways.Trunk-based development says integration should happen at least daily. There's one long-lived branch,
main. I branch for a few hours, open a small pull request, the pipeline builds and tests it, someone reviews it, and it merges. If the feature isn't finished, it ships dark behind a feature flag. Releases are just a build ofmainpromoted through environments, often tagged with a version.The mistake I see is teams saying they 'do CI' because a build server runs on every branch, while features sit on branches for three weeks. That's continuous building, not continuous integration: the integration still happens at the end, as one painful merge. So my default for a .NET web service is trunk-based with short-lived pull requests and flags. I'd keep something closer to Git Flow only for a NuGet library or desktop product where we really support 2.x and 3.x at the same time. The branch strategy should follow how you release, not the other way round."
| Git Flow | Trunk-based development | |
|---|---|---|
| Long-lived branches | main + develop |
main only |
| Feature branch life | Days to weeks | Hours to 1–2 days |
| Unfinished work | Stays on its branch | Merged, hidden behind a flag |
| Release | release/* branch, merged to main and develop |
Build of main, tagged, promoted through environments |
| Hotfix | hotfix/* from main, merged both ways |
Fix on main, roll forward (or short release branch cherry-pick) |
| Merge conflicts | Large, late | Small, early |
| Needs | Release manager discipline | Fast automated tests, flags, small PRs |
main is always releasable you can deploy any commit, which makes rollbacks and hotfixes ordinary events.| Situation | Why a branchier model helps |
|---|---|
| A NuGet package or SDK with several supported major versions | You need release/2.x and release/3.x to live side by side |
| Mobile or desktop apps with store review and fixed release trains | A stabilisation branch lets main keep moving |
| Regulated releases needing a frozen, signed-off code line | The release branch is the audited artefact |
Even then, many teams use release branches off trunk (cut late, only cherry-picked fixes) instead of full Git Flow with develop.
A team running a .NET 10 API on Git Flow merged develop into main every two weeks; each release took about a day of conflict fixing and regression testing, and roughly one release in four was rolled back. After moving to trunk-based with PRs under ~300 lines, required checks and feature flags, they deployed several times a day, and the median time from merge to production dropped from about 9 days to under 2 hours.
Checks whether the candidate understands branching as an integration-frequency trade-off tied to how software is released, not as a set of branch names to memorise.
Green flags
Red flags
mainA branch is cheap in Git (a pointer to a commit), but divergence is expensive. The cost of merging two lines of work grows with the number of changed lines on both sides and with how long they've drifted apart, because each side builds new code on assumptions the other side is changing.
Git Flow
main ●───────────────────────●──────────● (tags v1.3, v1.4)
\ / \ /
hotfix \ / ●──────●
\ /
release \ ●──●───● release/1.4
\ /
develop ●──●──●──●──●──●──●──●──●
\ / \ /
feature ●──●──● ●──●──●──● (lives for weeks)
Trunk-based
main ●─●─●─●─●─●─●─●─●─●─●─●─● (every commit releasable)
\ / \ / \ /
PR ● ● ● (lives for hours)
Martin Fowler's definition: every developer integrates into the mainline at least daily, and every integration is verified by an automated build and tests. A build server running on long-lived branches is not CI, because the integration (the merge) still happens rarely.
Trunk-based development is simply the branching model that makes this definition possible.
| Technique | What it does | .NET example |
|---|---|---|
| Feature flag | Code path exists but is switched off | Microsoft.FeatureManagement, [FeatureGate("NewCheckout")] |
| Branch by abstraction | Introduce an interface, build the new implementation behind it, switch over, delete the old one | IPaymentGateway with old and new adapters in DI |
| Dark launch | New endpoint deployed but not routed or linked | Endpoint not in the gateway yet |
| Expand/contract DB changes | Add before you remove, so old and new code both work | Add column, backfill, switch reads, drop later |
main: required status checks (build, tests, analysers), at least one review, no direct pushes, linear history if you like.main is the one that was tested against the latest main.commit on main ──► CI build ──► artefact (container image, tag sha-abc123)
│
├─► dev (auto)
├─► test (auto, smoke tests)
└─► prod (approval, slot swap / canary)
The same artefact moves through every environment; only configuration changes. Versions come from tags (e.g. MinVer or Nerdbank.GitVersioning reading Git history) rather than from branch names.
GitHub Flow is trunk-based in practice: branch from main, PR, merge, deploy. Teams that need to patch an older release cut a release/* branch from a tag only when needed and cherry-pick the fix from main, so main remains the single source of truth.
main in a GitHub repo: require a PR, one review and a passing status check.Microsoft.FeatureManagement.AspNetCore to a minimal API and hide a new endpoint behind a flag set in appsettings.json.git log --merges --since="30 days ago" --format="%h %ar %s" | head on a real repo and estimate average branch lifetime.v1.2.0; check the assembly version produced by dotnet build.Hiding unfinished work on main with a feature flag, so a short-lived branch can merge before the feature is done. The flag is temporary: it is created with the first PR, switched on per environment (ideally from Azure App Configuration so no redeploy is needed), and deleted with its if once the feature is fully released.
// Program.cs (.NET 10, Microsoft.FeatureManagement.AspNetCore 4.x)
using Microsoft.FeatureManagement;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFeatureManagement(); // reads the "feature_management" (or "FeatureManagement") section
var app = builder.Build();
app.MapGet("/orders/{id:int}", (int id) => Results.Ok(new OrderDto(id, "Shipped")));
// TEMPORARY release flag: owner @orders-team, remove after OrderTracking is 100% on in prod (ticket ORD-412).
// The new endpoint is merged and deployed, but switched off until the flag is enabled.
app.MapGet("/orders/{id:int}/tracking", async (int id, IFeatureManager features, CancellationToken ct) =>
await features.IsEnabledAsync("OrderTracking", ct)
? Results.Ok(new TrackingDto(id, "In transit"))
: Results.NotFound());
app.Run();
public sealed record OrderDto(int Id, string Status);
public sealed record TrackingDto(int OrderId, string State);
// appsettings.json: off by default; environments override it (App Configuration or environment variables)
{
"feature_management": {
"feature_flags": [
{ "id": "OrderTracking", "enabled": false }
]
}
}
A test that covers both flag states, so the dark code path is already tested before release:
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Xunit;
public sealed class TrackingFlagTests(WebApplicationFactory<Program> factory) : IClassFixture<WebApplicationFactory<Program>>
{
[Theory]
[InlineData(true, 200)]
[InlineData(false, 404)]
public async Task Tracking_respects_flag(bool enabled, int expected)
{
var client = factory.WithWebHostBuilder(b => b.ConfigureAppConfiguration((_, c) =>
c.AddInMemoryCollection(new Dictionary<string, string?>
{
["feature_management:feature_flags:0:id"] = "OrderTracking",
["feature_management:feature_flags:0:enabled"] = enabled.ToString()
}))).CreateClient();
var response = await client.GetAsync("/orders/1/tracking", TestContext.Current.CancellationToken);
Assert.Equal(expected, (int)response.StatusCode);
}
}
# A typical short-lived branch: hours, not weeks
git switch -c feat/order-tracking-endpoint
# ...small change + tests for both flag states...
git push -u origin feat/order-tracking-endpoint
gh pr create --fill # CI runs, a colleague reviews, it merges the same day
main at least daily and run CI on the merged result.main breaks often and people lose trust in it. Instead: Invest in a PR pipeline under ~10 minutes (unit tests plus WebApplicationFactory integration tests) and fix flaky tests first.develop branch "just in case" in a web service. Why it is wrong: It adds a second integration point and a merge ceremony with no benefit when only one version is in production. Instead: Deploy from main and use tags for versions.if branches and untested combinations. Instead: Give each release flag an owner and a removal ticket.WebApplicationFactory configuration and test both states.#if compiler symbols or separate build configurations instead of run-time flags. Why it is wrong: Each build becomes a different artefact, and you can't switch off a bad feature without redeploying. Instead: Use Microsoft.FeatureManagement with Azure App Configuration so turning a feature off is a config change, not a rollback.develop. Instead: Cut release branches late and only cherry-pick fixes that already landed on main.The branching model is a consequence of the release model. If you run one version in production and can deploy any time, every long-lived branch is pure cost, so trunk-based is the default. If you support several versions in the field, you need release lines, but they should be cut from trunk and receive cherry-picked fixes rather than living in a full Git Flow cycle.
What makes trunk-based work isn't the branch diagram; it's the guard rails: required checks, fast tests, merge queues, feature flags and expand/contract database changes. Measure it with DORA metrics: lead time for changes, deployment frequency, change failure rate and time to restore.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Trunk-based (+ flags) | Web APIs and services deployed continuously | Needs fast tests, flag hygiene | Several major versions supported in the field |
| GitHub Flow | Small teams, one deployable app | Same as trunk-based, lighter process | Fixed release trains |
| Release branches off trunk | Mobile apps, SDKs, regulated sign-off | Cherry-pick discipline | Services where you just roll forward |
| Full Git Flow | Packaged software with scheduled releases | Merge ceremony, late integration | Almost any continuously deployed service |
The pipeline restores three times, builds in Debug, runs dotnet format in a way that silently fixes files instead of failing, and publishes from a different build than the one it tested. I'd use global.json for the SDK, restore once with --locked-mode, build once in Release with --no-restore, then test and publish with --no-build. I'd run dotnet format --verify-no-changes so formatting drift fails the build, collect test results and coverage, and cache the NuGet folder.
A feature flag is a run-time switch around a code path. It lets you deploy code to production with the feature off and release it later by changing configuration, to a percentage of users or a group first.
In .NET, Microsoft.FeatureManagement gives you IFeatureManager.IsEnabledAsync, [FeatureGate] for endpoints, and feature filters: Percentage, TimeWindow and Targeting (users, groups, rollout percentage), plus variants for experiments. Azure App Configuration stores the flags centrally and the app refreshes them without a redeploy, using managed identity to connect.
The trade-off: flags make releases safe and reversible, but every flag doubles the paths to test. Release flags must have an owner and a removal date; only kill switches should live long.
Last updated 23 Nov 2026.