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
CODEOWNERSfile routes review requests for paths that need a specific owner. Thepayments/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
productionenvironment 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_groupevent in the run list — that's the first place to look when "main is broken but every PR was green."
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.
What is Supply Chain Security? Dependencies, SBOMs, and the Attack That Hit 2.6 Billion npm Downloads
Your application is only as secure as every package it depends on. In September 2025, attackers compromised 27 npm packages with 2.6 billion weekly downloads by phishing one maintainer.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
Lockfiles and Dependency Audits in Composer, uv and npm: What Each One Actually Pins, Checks and Refuses
I built the same deliberately outdated project in Composer, uv and npm, then audited, tampered with and drifted each lockfile. Composer now refuses to resolve vulnerable versions at all, uv and npm both caught a single changed hash, and Composer's lockfile recorded no hash for any of its seven...