Chapter 09Lesson 03~190 minutes

Merge Methods, Merge Trains, Mergeability Checks, Conflict Resolution, and Integration Strategies: Configuration, Design Choices, and Tradeoffs

Choose merge methods and cleanup policies deliberately by balancing traceability, bisectability, CI validity, branch hygiene, latency, compute cost, and operational recovery.

SquashSemi-linearTradeoffsThroughputBranch cleanupRecovery

Learning objectives

  • Choose among merge commit, semi-linear, fast-forward, and squash based on operational outcomes rather than visual preference.
  • Explain the CI-validity tradeoff between ordinary MR pipelines, automatic rebase, merged-results pipelines, and merge trains.
  • Compare web conflict resolution with local Git based on complexity, observability, and recovery needs.
  • Decide when automatic source-branch deletion is safe and when evidence retention matters more.
  • Use a decision table that includes maintainability, security, reliability, compatibility, performance, and cost.
Availability baseline (verified 2026-08-21). Merge commit, merge commit with semi-linear history, fast-forward merge, squash options, ordinary merge-request pipelines, conflict resolution, auto-merge, merge checks such as pipeline/thread requirements, and source-branch cleanup are available on GitLab Free across GitLab.com, Self-Managed, and Dedicated. Merged results pipelines and merge trains are Premium/Ultimate. GitLab 19.2 documents automatic rebase before merge for semi-linear and fast-forward methods as generally available; older Self-Managed versions can differ. The mandatory chapter path therefore uses Free merge methods, local conflict resolution, and ordinary MR/API evidence, while merge trains are optional or simulated.

1. Start with the invariant you want to preserve

Do not begin with “we like clean history.” Begin with operational invariants: must every reviewed source commit remain identifiable? Must the target be strictly linear? Must CI test the exact candidate bytes that will land? Must releases be traceable to a merge commit? How expensive is rerunning pipelines?

2. Merge-method tradeoffs

Choice Strengths Costs / risks Good fit
Merge commit Preserves branch topology and source commits; easy to identify an MR boundary. Noisy graph in high-volume repositories; target SHA differs from source tip. Teams valuing explicit integration commits and forensic traceability.
Semi-linear Clean first-parent progression plus explicit merge commits. Requires source to be up-to-date/rebasable; extra rebase work. Teams wanting branch boundaries without merging stale bases.
Fast-forward Strictly linear target; source commits remain first-class. No explicit merge commit; source must be up-to-date/rebased. Trunk-like workflows with disciplined source branches.
Squash One logical target commit per MR; easy whole-change revert. Original source SHAs are not target commits; poor fit for long-running branches. Feature branches with noisy intermediate commits.

3. Squash is an orthogonal policy dimension

GitLab can set squash to never, always, default on, or default off. Under merge-commit mode, squashing can create a squash commit and then a merge commit. Under fast-forward mode, the target can advance to the squash commit. Therefore “we squash” does not fully describe the target graph.

Long-running source branches are a poor squash candidate because the target receives a new commit SHA representing prior source work while the source branch still contains the original commits. Continued development can produce confusing divergence unless the branch is rebased or synchronized.

4. CI validity versus friction and compute

Strategy Tier Candidate tested Latency / compute implication
MR pipeline Free Source branch only Lowest extra integration cost; target advancement can make evidence stale.
Automatic rebase before merge Free in current GitLab 19.2 Server-side rebased result is merged; CI is not automatically rerun on that rebased result. Reduces manual rebase friction but can weaken exact-candidate evidence unless compensated.
Merged results pipeline Premium/Ultimate Temporary source+latest-target merge result More representative candidate; extra pipeline compute.
Merge train Premium/Ultimate Ordered candidate including earlier train entries Best high-throughput ordering confidence; more queueing and compute.
Critical current behavior: GitLab 19.2 automatic rebase before merge does not rerun CI on the server-side rebased result. If exact post-rebase validation is a requirement, use a design that explicitly validates the candidate, such as merge trains where available.

5. Merge trains: throughput versus latency

Merge trains improve confidence when many MRs target the same branch. Their value rises with concurrency: each car is tested in the context of earlier train cars. The cost is extra pipelines, queue management, and possible restarts when earlier entries fail or leave the train.

A small team merging twice a day may gain little from a train. A monorepo integrating dozens of ready changes per hour may gain substantial reliability despite compute cost. Measure queue time, failed-car rate, pipeline duration, and wasted compute before deciding.

6. Web editor versus local Git

Option Use when Avoid when
GitLab conflict UI Small UTF-8 text conflict, clear semantic choice, fast review. Binary/large files, renames, many files, generated code, or resolution needs tests/refactoring.
Local merge/rebase Complex conflict, need full editor/tests/history tools, need reproducible commands. Only when operator understands merge/rebase consequences; preserve SHAs first.
GitLab Duo-assisted conflict resolution Optional AI-assisted path where available. Never treat generated resolution as trusted; review/test exactly like human-authored code.

7. Automatic source-branch cleanup versus forensic convenience

Automatic deletion is ideal for short-lived feature branches after successful merge because the target/MR preserve durable history. Retain a branch temporarily when an incident, release verification, multi-step migration, or dependent branch still needs the named ref. Either way, record the source tip before deletion and prove merged commits remain reachable.

SOURCE_SHA="$(git rev-parse origin/ch09-feature)"
TARGET_SHA="$(git rev-parse origin/main)"
printf 'source=%s
target=%s
' "$SOURCE_SHA" "$TARGET_SHA"

# Before deleting the source pointer, prove reachability from the target.
if git merge-base --is-ancestor "$SOURCE_SHA" "$TARGET_SHA"; then
  echo "source tip is reachable from target"
else
  echo "source tip is NOT an ancestor; inspect merge/squash semantics before cleanup"
fi

8. Worked production decision

Scenario: a regulated service needs auditable MR boundaries, retains individual developer commits, averages eight merges/day, and cannot justify paid merge trains. The team also requires the source to be up-to-date before integration.

Criterion Decision Reason
History Semi-linear merge commit Keeps explicit MR boundary and source commits while requiring an up-to-date source.
Squash Default off Preserves reviewed developer commit identities.
CI MR pipeline + explicit rebase/rerun when target advances Free-compatible; operational procedure compensates for stale-source risk.
Conflict resolution Local for nontrivial conflicts Allows full tests and preserves exact repair commit.
Cleanup Delete after evidence/reachability check Reduces clutter without sacrificing traceability.
Paid extension Merge train if throughput grows Adds ordered integration validation when cost/volume justify it.

Knowledge check

Why might semi-linear be preferable to plain merge commit for a regulated service?

What risk does automatic rebase-before-merge create for strict CI evidence?

When is squash a poor fit?

What metric helps determine whether merge trains are worth their cost?

What must be proven before deleting a branch used for diagnostics?

Summary

Integration policy should follow explicit invariants: history shape, candidate validity, traceability, throughput, and recovery. Merge trains are a scaling/reliability tool, not a universal default; squash is not a complete merge strategy by itself; and branch cleanup is safe only after evidence and reachability are proven.

Official references

Next lesson

Diagnose integration failures without destroying evidence

Lesson 4 uses stale pipelines, unexpected squash/merge identities, semantic conflict mistakes, train-state confusion, and premature cleanup as concrete diagnostic cases.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.