Skip to content

Lesson 6 of 13 · 20m

Merge Gates: Branch Protection and Merge Queues

Checks block nothing until branch protection names them — and the merge queue is what makes green PRs stay green after they combine.

A green check on a pull request blocks nothing. Checks are decoration until branch protection makes them binding — and the configuration details decide whether the gate works or merely looks like it works.

What protection actually does

Repo Settings → Branches — or the newer Rulesets UI — gives you: require a pull request, require status checks to pass, require conversation resolution, require approvals. The trap hides inside "require branches to be up to date before merging." With it on, every PR must contain the latest main — so merging PR A instantly stale-dates PR B, which must re-run the whole pipeline; at any real merge volume this serializes everything into a queue nobody designed.

Turn it off and the opposite failure appears: two green PRs merge back-to-back and break main together. Each tested against the old main, and the combination is a semantic conflict neither PR ever saw — PR A adds a required parameter, PR B calls the function without it. Both green; main red.

The merge queue is the designed answer

GitHub's merge queue — generally available since July 2023 — fixes this without the serialize-everything tax. Instead of merging a PR that tested head-against-old-main, the queue builds a merge group: the speculative merge commit of the PR plus latest main plus everything already queued, and runs the checks on that. Whichever PR breaks the combination gets ejected; the queue continues. GitLab calls the same idea merge trains; the Rust project's bors bot invented the pattern years before either shipped it as a feature.

The practical consequence that bites everyone once: your on: triggers need merge_group: added, or the queue runs nothing and nothing merges. The workflow exists, the queue exists, and the checks never fire because the event isn't subscribed.

Check names are an API

Required checks match by name — the job name, including matrix values: test (node 20, ubuntu-latest). Rename the job and protection silently stops requiring it; rename a matrix leg and the required check waits forever on a name that no longer exists. Treat check names like a public API: stable, deliberate, greppable in the ruleset.

The rest of the ruleset worth setting

  • Require approvals — one is the floor; a CODEOWNERS file routes review requests for paths that need a specific owner. The payments/ directory should not merge on a random +1.
  • Require conversation resolution — forces review threads to close before merge, killing the "addressed later" category of lost feedback.
  • Require signed commits only if your org already signs — otherwise it's friction that buys nothing.
  • Don't enable both "require up to date" and the merge queue — the queue supersedes it.
  • Forked-PR approval — workflows on external contributions should require approval for first-time contributors (the public-repo default) before secrets-bearing jobs ever run.
  • Bypass actors and block force pushes — define who can break the glass (admins, a release role) and forbid force pushes on protected branches; a force push is history rewrite on the branch everyone trusts.

Field notes

  • Environment protections are a different system — required reviewers on the production environment gate deploys, not merges. Both exist; don't confuse them.
  • Rulesets can be enforced at org level, where a repo admin can't disable them — the right direction for the checks that actually matter.
  • A merge queue run appears as a merge_group event in the run list — that's the first place to look when "main is broken but every PR was green."

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.