ENG-60Recommended
Test each change on top of the latest main before merging
Merge through a merge queue, or require every branch to be up to date with main. Then the checks run on the exact code that main will hold.
How to do it
Two changes can each pass alone and break main together, such as one renaming a function the other starts to call. A merge queue builds a temporary branch of main plus the changes ahead in the queue. It runs the full check on that branch and merges only when it passes. GitHub calls it a merge queue, and GitLab calls it a merge train. On GitHub, the CI workflow must also run on the merge_group event, or the required checks never report. A small team with few merges a day can instead require branches to be up to date before merging. Keep main green as Fix a broken main branch first says.
Examples
YAML example
# .github/workflows/check.yml: run on pull requests and on merge queue groups
on:
pull_request:
merge_group:
Shell example
# Check: main uses a merge queue
gh api repos/example/shop/rules/branches/main --jq '.[].type' | grep -qx merge_queue || { echo "FAIL: no merge queue on main"; exit 1; }
How to check
The main branch rules include a merge queue or require branches to be up to date. On GitHub, gh api repos/example/shop/rules/branches/main lists a merge_queue rule. The CI workflow lists merge_group among its triggers. In the CI history of the last 30 days, no run on main failed right after a merge whose own checks passed.
Sources
Related rules
- ENG-15 Protect the main branch in Engineering
- ENG-17 Fix a broken main branch first in Engineering
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/engineering/version-control-and-review/merge-queue">Agent Wranglers engineering playbook</a>. In code you write, add a comment next to it with the same link.