How to set up merge queues on GitHub (and automate them with Graphite)

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite

Table of contents

A merge queue is an automated tool that manages the merging of pull requests (PRs) into your main branch. Instead of merging directly, pull requests are placed into a queue. Each queued PR is then combined with the current main branch state and other queued PRs into temporary merge branches. Continuous Integration (CI) checks run against these combined branches. Only PRs passing these checks are automatically merged, ensuring the main branch remains stable and continuously deployable.

Merge queues offer several advantages:

  • Prevent merge conflicts and broken builds by verifying combined changes beforehand.
  • Reduce manual rebasing and rerunning tests, saving developers' time.
  • Streamline deployments by ensuring only passing builds reach production.

Follow these steps to set up a merge queue on GitHub:

  • Go to your GitHub repository and navigate to Settings → Branches.
  • Create or edit the branch protection rule for your main branch.
  • Enable Require status checks to pass before merging.
  • Enable Require merge queue and configure the merge method (merge, squash, or rebase).

Your GitHub Actions workflows must handle both pull_request and merge_group events:

Terminal
on:
pull_request:
merge_group:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm test

For other CI providers, ensure workflows trigger on branches with the prefix gh-readonly-queue/{base_branch}.

Once checks pass, click Merge when ready on your PR, or use the CLI:

Terminal
gh pr merge

GitHub automatically places the PR into the merge queue.

You can:

  • View your merge queue status via the Branches page or directly from PR pages.
  • Remove a PR from the queue if necessary.
  • Prioritize a PR by moving it to the top, triggering a new combined build.

Graphite offers advanced, automated merge queue capabilities that complement GitHub with additional benefits like stack awareness, fast-forward merges, and intelligent batching for CI checks.

  • Stack-awareness: Automatically rebases and merges dependent PRs.
  • Batching & parallel CI: Saves time and reduces CI costs.
  • Hot-fix support: Easily push critical changes to the front of the queue.
  • User-friendly UI: Offers intuitive controls within GitHub and Graphite.
  1. Install and authorize the Graphite GitHub app.
  2. Disable GitHub's native merge queue in your repo settings.
  3. Enable Graphite's merge queue via Graphite's repo settings, selecting your desired merge strategy (fast-forward, squash, or rebase).
  • Add PRs via Graphite's UI or by using GitHub labels.
  • Monitor and manage your queue through Graphite's intuitive dashboard, easily pausing, reprioritizing, or removing PRs.
  • GitHub Merge Queue: Simple setup, ideal for smaller teams or projects.
  • Graphite Merge Queue: Ideal for teams needing advanced automation, stack-based workflows, or heavy CI optimizations.

Implementing a merge queue dramatically improves your repository's stability and developer productivity. Whether you choose GitHub's built-in merge queue for simplicity or Graphite for greater automation, adopting this approach is a significant step toward smoother, more reliable deployments.

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