📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the difference between Git Flow and trunk-based development? Explain how each one uses branches, how releases work, and why most teams now prefer short-lived branches merged into main.

Compares Git Flow and trunk-based development: branch types, release flow, merge pain, CI implications and why short-lived branches won.

Junior Theory Beginner branching-strategy ci-cd devops git git-flow trunk-based-development

🎯 Key points

  • Git Flow: long-lived main and develop plus feature, release and hotfix branches
  • Trunk-based: everyone integrates into main at least daily via short-lived branches (hours to 1-2 days)
  • Long-lived branches delay integration, so merge conflicts and integration bugs pile up
  • Fast automated tests on every PR are what make trunk-based safe; Git Flow hides weak tests until release
  • Feature flags let trunk-based teams merge unfinished work and still deliver continuously
  • Release from main by tag or build artefact, not by a release branch merge dance
  • Git Flow still fits versioned products with several supported releases
  • DORA research links trunk-based development with higher delivery performance

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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, and develop, where the next release is assembled. Features live on their own branches until they're done, then merge into develop; when you're ready to ship you cut a release/1.4 branch, stabilise it, and merge it into both main and develop. Urgent fixes go on hotfix branches 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 of main promoted 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."


The two models side by side

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

Why short-lived branches won

  • Merge cost grows faster than branch age. Two branches that each change 30 files for three weeks conflict in ways nobody can review properly.
  • Feedback arrives early. A failing test caused by someone else's change shows up the same day, while the context is fresh.
  • Small PRs get real reviews. A 150-line PR gets read; a 3,000-line PR gets an "LGTM".
  • Continuous delivery depends on it. If main is always releasable you can deploy any commit, which makes rollbacks and hotfixes ordinary events.
  • Evidence. The DORA State of DevOps research has repeatedly linked trunk-based development (few active branches, short life, merging at least daily) with higher deployment frequency and lower change failure rate.

When Git Flow (or a variant) still fits

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.

Production example

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.

🔍 What the interviewer is checking

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

  • Explains that long-lived branches delay integration and make merges larger and riskier
  • Mentions feature flags or branch by abstraction for unfinished work
  • Knows when Git Flow still makes sense (multiple supported versions)
  • Connects the choice to CI/CD, small PRs and DORA-style outcomes

Red flags

  • Thinks a build server on every branch equals continuous integration
  • Claims one model is always right regardless of release model
  • Can't say how unfinished features stay safe on main

📚 Learn in depth

1. What a branch really costs

A 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)

2. Continuous integration, properly defined

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.

3. How unfinished work stays safe on main

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

4. Guard rails that make trunk-based safe

  • Branch protection on main: required status checks (build, tests, analysers), at least one review, no direct pushes, linear history if you like.
  • Fast pipelines: if the PR build takes 40 minutes people batch changes. Aim for under ~10 minutes with test splitting and NuGet caching.
  • Merge queues (GitHub merge queue, Azure DevOps has build validation) so the commit that lands on main is the one that was tested against the latest main.
  • Small PRs as a team norm, and stacked PRs for bigger features.

5. Releasing from trunk

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.

6. GitHub Flow and release branches

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.

Try it yourself

  1. In a scratch repo, make two branches that each rename and edit the same C# class over ten commits, then merge them. Note how long the conflict takes to resolve compared with merging after one commit each.
  2. Turn on branch protection for main in a GitHub repo: require a PR, one review and a passing status check.
  3. Add Microsoft.FeatureManagement.AspNetCore to a minimal API and hide a new endpoint behind a flag set in appsettings.json.
  4. Run git log --merges --since="30 days ago" --format="%h %ar %s" | head on a real repo and estimate average branch lifetime.
  5. Add MinVer to a project and tag a commit v1.2.0; check the assembly version produced by dotnet build.

💻 Code

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

⚠ Common mistakes

  • Mistake: Calling it CI because a build runs on every feature branch. Why it is wrong: Integration still happens at the end in one big merge. Instead: Merge into main at least daily and run CI on the merged result.
  • Mistake: Adopting trunk-based development without fast, reliable tests. Why it is wrong: 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.
  • Mistake: Keeping a 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.
  • Mistake: Merging half-finished features without a flag. Why it is wrong: Users see broken behaviour on the next deploy. Instead: Hide them behind a flag, branch by abstraction or a dark endpoint.
  • Mistake: Never deleting feature flags. Why it is wrong: Old flags turn into permanent if branches and untested combinations. Instead: Give each release flag an owner and a removal ticket.
  • Mistake: Testing only the flag-off path in .NET integration tests. Why it is wrong: The new code ships untested and fails the day the flag is switched on. Instead: Override the flag per test with WebApplicationFactory configuration and test both states.
  • Mistake: Using #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.
  • Mistake: Long-running release branches that receive new features. Why it is wrong: They become a second develop. Instead: Cut release branches late and only cherry-pick fixes that already landed on main.
  • Mistake: Choosing a branching model by habit. Why it is wrong: The model should follow how many versions you support and how you release. Instead: Pick trunk-based for continuously deployed services, release branches for multi-version products.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate says main must always stay releasable. Why: Checks whether the candidate knows what the CI pipeline guarding main should actually do.
    How to answer

    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.

  2. When: Candidate mentions feature flags for unfinished work. Why: Checks whether the candidate can actually implement and retire the flags that trunk-based development depends on.
    How to answer

    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.

↩ Usually asked after

More in CI/CD

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me