Skip to main content
The merge queue provides controlled, safe merging of pull requests with intelligent conflict prediction, automated testing, priority handling, and batch optimization.

Overview

The merge queue:
  • Prevents merge conflicts by analyzing PRs and determining optimal merge order
  • Tests PRs before merging to prevent broken builds
  • Batches multiple PRs for efficient CI usage with automatic bisection on failure
  • Handles priority ordering with customizable priorities (0-100)
  • Auto-rebases PRs to stay up-to-date with the target branch
  • Provides detailed status and statistics

How It Prevents Conflicts

The merge queue uses an intelligent algorithm to prevent merge conflicts:

1. PR Analysis

When a PR is added to the queue, the system analyzes:
Conflict-prone areas are automatically identified:
  • Lock files (package-lock.json, yarn.lock, pnpm-lock.yaml)
  • Generated files (*.generated.ts)
  • Schema and migration files
  • High-churn files (100+ lines changed)

2. Conflict Prediction

Before processing, the queue predicts conflicts between all PR pairs:

3. Optimal Ordering

The queue uses a greedy algorithm to determine the safest merge order:

4. Speculative Merging

The queue performs merges in an isolated worktree:
  1. Create temporary branch from target
  2. Cherry-pick commits in optimal order
  3. If conflict occurs, try reordering or fall back to merge commit
  4. Push speculative merge for CI testing
  5. Only update target branch if CI passes

5. Batch Processing with Bisection

When batching multiple PRs, if one fails:

Quick Start

Commands

Add to Queue

Remove from Queue

Check Status

List Queue

Queue Statistics

Configuration

View or update merge queue settings:

Enable/Disable

Queue States

PRs in the queue go through these states:

Strategies

The merge queue supports different strategies:

Sequential

Tests and merges one PR at a time. Safest but slowest.
Best for: Critical branches, low-volume repos

Optimistic

Groups multiple PRs together for testing. Uses bisection on failure.
Best for: High-volume repos with good CI Analyzes conflicts and determines optimal merge order, then batches.
Best for: Most use cases - balances safety and speed

Auto-Merge Modes

Control when the queue processes:

Auto (Default)

Queue processes automatically when PRs are ready.

Manual

Wait for explicit trigger to process.

Scheduled

Only process during specific time windows.

Priority System

Higher priority PRs are processed first:
Within the same priority level, conflict analysis determines order.

Configuration Options

Web UI Integration

The merge queue is integrated into the PR page:

From the Action Card

  • Merge Now: Direct merge to branch (bypasses queue)
  • Add to Queue: Queue for automated, conflict-free merging
  • Add with Priority: Queue with high priority (jumps ahead)

Queue Status

When a PR is in the queue, the action card shows:
  • Current position and state
  • Progress bar for active states
  • Estimated wait time
  • Remove from queue option
A compact status indicator shows:
  • Queue position
  • Processing state
  • Link to queue settings

Workflow Example

Adding PRs to Queue

Monitoring Queue Progress

Handling Failures

If your PR fails in the queue:

JSON Output

For scripting and automation:

Integration with CI/CD

The merge queue integrates with wit’s built-in CI:

Required Checks

Configure which CI checks must pass:

Best Practices

For Fast Merges

  • Keep PRs small and focused
  • Ensure CI is fast and reliable
  • Use the adaptive strategy for high-volume repos

For Safety

  • Enable auto-rebase to catch conflicts early
  • Require status checks
  • Use the sequential strategy for critical branches

For Teams

  • Set clear priority guidelines (80+ for urgent, 50 for normal)
  • Monitor queue statistics regularly
  • Use scheduled mode to avoid merges during critical periods

Technical Details

Conflict Score Calculation

Optimal Order Algorithm

  1. Build NxN conflict matrix for N PRs
  2. Greedy selection: pick PR with lowest sum of conflicts
  3. Repeat until all PRs ordered
  4. PRs touching unique files go first
  5. PRs touching shared files go last (built on stable base)

Speculative Merge Process

  1. Create isolated git worktree from target branch
  2. For each PR in optimal order:
    • Try cherry-picking each commit
    • If fails, fall back to merge commit
    • If still fails, report failure
  3. Push speculative merge to temp branch
  4. Run CI on speculative merge
  5. If CI passes, fast-forward target branch

Requirements

The merge queue requires:
  • wit server running (wit serve)
  • Database connected (PostgreSQL)
  • CI/CD configured (optional but recommended)
  • Branch protection enabled (recommended)