GitHub·7 min read·

High-Velocity Trunk-Based Development with GitHub Merge Queues and Rulesets

Prevent speculative CI breakage and broken mainline builds in fast-moving engineering teams using speculative merge trains and branch rulesets.

NB

Netbay Cloud Team

Netbay Engineering

On this page

In fast-moving software teams practicing trunk-based development, multiple pull requests are approved and merged every hour. This frequently creates a frustrating phenomenon known as semantic merge conflict:

  • PR A is tested against 'main' and passes all tests.
  • PR B is tested against 'main' independently and passes all tests.
  • Both PRs merge into 'main' five minutes apart.
  • Main breaks immediately because PR A renamed a method that PR B called.

Traditional solutions required developers to manually rebase and wait for CI to re-run before merging, creating massive productivity bottlenecks.

GitHub Merge Queues combined with modern Repository Rulesets eliminate this completely through speculative merge trains.

How Speculative Merge Trains Work

When developers click 'Merge when ready', PRs enter an automated queue:

  • Speculative Branch Assembly: If PR A and PR B are in queue, GitHub simultaneously tests:

1. main + PR A (Train 1) 2. main + PR A + PR B (Train 2)

  • Optimistic Concurrency: If Train 1 passes, PR A merges immediately. If Train 2 also passes, PR B merges immediately after without waiting for a rebase.
  • Outlier Ejection: If Train 2 fails due to a semantic conflict between A and B, GitHub automatically ejects PR B from the train and tests PR C against PR A, keeping the mainline pipeline moving at maximum velocity.
GitHub Merge Queue Speculative Train Architecture Merge Queue PR #101: auth refactor PR #102: billing API Status: Queued Speculative CI Engine Job 1: test(main + #101) Job 2: test(main + #101 + #102) Parallel Speculative Execution Zero Manual Developer Rebasing Mainline Integrity Fast-Forward Commits Linear Git History Main Never Breaks: 100% Repository Ruleset Enforcement Enforces linear commit history, mandatory code owner approvals, and signed commits Bypasses traditional branch locks, letting engineers ship 50+ PRs daily with zero stress

GitHub Actions Merge Group Trigger

To enable merge queue testing, add the 'merge_group' trigger to your test workflow:

yaml
# .github/workflows/verify.yml
name: Continuous Verification

on:
  pull_request:
    branches: [main]
  merge_group:
    types: [checks_requested]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run Production Test Suite
        run: |
          echo "Running speculative integration checks..."
          npm test
          npm run build

Configuring Repository Rulesets

Under GitHub Repository Settings -> Rules -> Rulesets:

  1. Target: Branch 'refs/heads/main'.
  2. Require linear history: Enforces squash or rebase merges to maintain a clean Git history.
  3. Require merge queue: Set merge method to 'Squash', maximum parallel groups to 5, and timeout to 45 minutes.
  4. Block force pushes and branch deletions.
Expand
Software Delivery Pipeline and Merge Trains
Trunk based development and merge trains

Video Reference on Trunk-Based Development & CI

Learn the principles of high-velocity trunk-based development and continuous integration:

Continuous Integration and Trunk Based Development
YouTube

Combining GitHub Merge Queues with repository rulesets guarantees that your mainline branch stays green 100% of the time while enabling rapid shipping.

Deploy continuous releases to Netbay high-speed cloud VPS instances with instant automated webhooks at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance