Graphite Reviewer is now Diamond

Benefits of a merge queue vs. direct merging

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite

In software development, managing how code changes are integrated into the main branch is crucial for maintaining stability and efficiency. Two primary strategies are:

  • Direct merging: developers merge pull requests (PRs) into the main branch as soon as they're approved.
  • Merge queues: PRs are added to a queue and merged sequentially after passing all required checks.

This guide compares these strategies, highlighting their benefits and trade-offs.

A merge queue automates the process of integrating PRs into the main branch. When a PR is added to the queue:

  1. A temporary branch is created, combining the PR with the latest main branch changes.
  2. Continuous integration (CI) checks run on this combined branch.
  3. If checks pass, the PR is merged; otherwise, it's removed from the queue.

This ensures that each PR is tested in the context of the most recent codebase, reducing the risk of integration issues.

Merge queues ensure that only PRs passing all checks against the latest code are merged, preventing broken builds.

Example: if "PR A" is merged directly and introduces a bug, subsequent PRs might fail due to this bug. A merge queue would catch such issues before merging.

Developers don't need to constantly rebase their PRs with the latest main branch changes; the merge queue handles this automatically.

By testing PRs in the context of the latest code, merge queues reduce the number of failed builds and the need for reruns.

For teams with many contributors and frequent PRs, merge queues manage the integration process efficiently, ensuring orderly merges.

  • Speed: Immediate merging without waiting in a queue.
  • Simplicity: Fewer tools and configurations required.
  • Risk of conflicts: Merging without testing against the latest code can introduce conflicts or break the build.
  • Manual overhead: Developers may need to frequently update their PRs to keep up with the main branch.
  • Inconsistent CI results: Tests may pass in the PR branch but fail after merging due to changes in the main branch.
StrategyBest for
Merge queuesLarge teams, frequent PRs, critical systems
Direct mergingSmall teams, infrequent changes, less critical systems

Consider your team's size, the frequency of changes, and the criticality of your system when choosing an integration strategy.

aspectMerge queueDirect merging
CI reliabilityHigh (tests run on latest code)Medium (tests may not reflect latest)
Developer overheadLow (automated updates)High (manual rebases may be needed)
Merge conflictsRare (conflicts caught before merging)possible (conflicts may arise post-merge)
Integration speedModerate (depends on queue length)Fast (immediate merges)

Automating the merge process through merge queues offers:

  • Consistency: Ensures all PRs meet the same standards before merging.
  • Efficiency: Reduces manual tasks, freeing developers to focus on coding.
  • Reliability: minimizes the risk of introducing errors into the main branch.

Several tools facilitate merge queue implementation:

  • Graphite: Offers an AI-powered pull request toolchain with a merge queue tool, which automates merges and maintains branch stability. (graphite.dev)

  • GitHub merge queue: Native support for merge queues, integrating with GitHub Actions for CI checks. (docs.github.com)

  • Mergify: provides advanced merge queue features, including batching and prioritization. (docs.mergify.com)

Choosing between merge queues and direct merging depends on your team's needs and workflow complexity. Merge queues offer enhanced stability and automation, making them ideal for larger teams and critical projects, while direct merging may suffice for smaller teams with simpler workflows. You should evaluate your requirements to select the most suitable code integration strategy.

Built for the world's fastest engineering teams, now available for everyone