Sub topic 3
Merge groups and temporary branches
This chapter assumes you know Git branching and merging, pull requests on GitHub, and the basics of GitHub Actions. It covers what the queue builds and where that build lives.
The merge group
A merge group is the unit of work a merge queue tests. It is a temporary commit that combines three things:
- the latest commit on the base branch (usually
main), - the changes from every pull request ahead of yours in the queue,
- the changes from your pull request.
Checks run against that combined commit, not against your pull request branch. If they pass, the queue fast-forwards the base branch to the commit (or to an equivalent one, depending on the merge method). That is why the result you tested is what lands.
Temporary branches
For each merge group, GitHub creates a branch under the gh-readonly-queue/ prefix. The name follows this pattern:
gh-readonly-queue/main/pr-123-<sha>The parts are the base branch, a pull request number, and a commit SHA. Treat the name as an identifier, not something to parse.
These branches have these properties:
- GitHub creates them. You do not create or push to them, and they are read-only.
- Each one points at a commit that already includes the work queued ahead of it.
- They are deleted after the group merges or is removed from the queue.
Each queued pull request gets its own group, built on the group before it. Pull request B is tested on top of A, and C is tested on top of A and B.
Because B's group contains A, the queue can run checks for A and B in parallel. If A fails, B's build is no longer valid. GitHub removes A and rebuilds B without it.
What your workflow sees
When the queue creates a merge group, it fires the merge_group event. Your workflow runs on the temporary commit, not on the pull request. The event payload describes the group:
name: Inspect merge group
on:
merge_group:
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Show merge group details
run: |
echo "Ref: ${{ github.ref }}"
echo "Head SHA: ${{ github.event.merge_group.head_sha }}"
echo "Base SHA: ${{ github.event.merge_group.base_sha }}"
echo "Base ref: ${{ github.event.merge_group.base_ref }}"
git log --oneline -n 5head_sha is the merge group commit. base_sha is the base branch commit the group was built on. The checkout step gets the group commit, so git log shows the queued work stacked on top of main.
Why the separate event matters
A workflow that listens only for pull_request never runs on a merge group. The required check then never reports on the temporary commit, and the group waits until it times out. The fix is to add the merge_group trigger, which later chapters cover in detail.
Two consequences are worth knowing now:
- Checks on the pull request and checks on the merge group are separate runs with separate results. A green pull request does not satisfy the queue.
- Anything that depends on pull request context, such as
github.event.pull_request, is empty in amerge_grouprun. Use themerge_grouppayload instead.
Quick reference
| Item | Value |
|---|---|
| Branch prefix | `gh-readonly-queue/` |
| Created by | GitHub, when a pull request enters the queue |
| Event that triggers workflows | `merge_group` |
| Lifetime | Until the group merges or is removed |
| Contents | Base branch, earlier queued pull requests, your pull request |
Exercise
Pull requests A, B, and C are queued in that order, and A's group fails its checks. What happens to B's merge group, and why?
Show answer
B's group contained A's changes, so its result is no longer valid. GitHub removes A from the queue and rebuilds B's group on the base branch plus any pull requests still ahead of B (here, none). C is rebuilt on top of B in the same way. Then the checks run again for the rebuilt groups.
Exercise
A pull request shows all checks green, but its merge group sits waiting for a required check to report. The workflow is triggered only by pull_request. What is wrong, and what is the fix?
Show answer
The workflow does not run on the temporary merge group commit, so the required check never reports there. Add merge_group: to the workflow's on: block (the only activity type is checks_requested, so types can be omitted).