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:- 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:- Create temporary branch from target
- Cherry-pick commits in optimal order
- If conflict occurs, try reordering or fall back to merge commit
- Push speculative merge for CI testing
- 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:| State | Description |
|---|---|
pending | Waiting in queue for earlier PRs |
preparing | Building speculative merge commit |
testing | CI tests running on speculative merge |
ready | Tests passed, ready to merge |
merging | Currently updating target branch |
completed | Successfully merged |
failed | Tests failed or merge conflict |
cancelled | Removed from queue |
Strategies
The merge queue supports different strategies:Sequential
Tests and merges one PR at a time. Safest but slowest.Optimistic
Groups multiple PRs together for testing. Uses bisection on failure.Adaptive (Recommended)
Analyzes conflicts and determines optimal merge order, then batches.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:Configuration Options
| Option | Description | Default |
|---|---|---|
--strategy | Merge strategy (sequential, optimistic, adaptive) | adaptive |
--batch-size | Maximum PRs per batch | 5 |
--min-wait | Minimum seconds before processing | 60 |
--auto-rebase | Auto-rebase PRs before testing | true |
--delete-branch | Delete branch after merge | true |
--auto-merge-mode | When to process (auto, manual, scheduled) | auto |
--required-checks | CI checks that must pass | none |
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
Sidebar Card
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
- Build NxN conflict matrix for N PRs
- Greedy selection: pick PR with lowest sum of conflicts
- Repeat until all PRs ordered
- PRs touching unique files go first
- PRs touching shared files go last (built on stable base)
Speculative Merge Process
- Create isolated git worktree from target branch
- For each PR in optimal order:
- Try cherry-picking each commit
- If fails, fall back to merge commit
- If still fails, report failure
- Push speculative merge to temp branch
- Run CI on speculative merge
- 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)
Related
- wit pr - Pull request management
- wit ci - CI/CD configuration
- wit protect - Branch protection