How to Merge Stacked PRs
Use our how-to guide for instructions on merging stacked PRs. Learn about queueing actions, core merge behaviors for stacked PRs, and separating merge commits.
Aviator offers an open-source CLI for managing stacked PRs within GitHub. When used alongside Aviator MergeQueue, it simplifies the process of validating and merging those stacked PRs (or subset of those stacked PRs) together.
When requested to merge stacked PRs, Aviator will validate all the stacked PRs as if they were a single PR, and then merge them together after validation. The merge behavior may be slightly different depending on the queue mode.
Queueing action
To merge a subset of the stack, request a merge for the topmost PR in that subset. So for instance, if your stack is:
master <- PR#1 <- PR#2 <- PR#3 <- PR#4Requesting a stack-merge action for PR#3 will validate PR#1, PR#2 and PR#3 leaving PR#4 untouched. After merging, the stack would look like:
master <- PR#4There are a few ways to request queueing a stack of PRs.
Chrome Extension (recommended): This is the simplest way to request way since the user experience for this is very similar to merging a regular PR. Go to
PR#3from above example in GitHub and click "Queue pull request" button:

GitHub Label: You can also queue the stack the same way using GitHub label like you would a single PR. To do so, just apply the label at the top PR that would want to merge with the stack. In the example above, apply the label on
PR#3.CLI: Another way to queue the PR is via the
avcommand line. Simply checkout the branch associated withPR#3and run the command:
av pr queueNote that, using this command requires authenticating the CLI with your Aviator account.
Slash command: A stack or sub-stack can also be merged by commenting a slash command from the GitHub interface:
/aviator mergeMerge behavior
Depending on the queue mode being used, the merge behavior for stacked PRs can vary.
Sequential mode (default mode)
Taking the example above, in sequential mode:
Aviator will consider
PR#1,PR#2andPR#3as a single PR in the queue.When this PR reaches the top of the queue, Aviator only updates
PR#3with the target branch (mainline), and run the CI.Once the CI passes, Aviator will change the base branch of
PR#3and merge itSince
PR#3is stacked on top ofPR#1andPR#2, merging PR#3 also merges all the changes associated withPR#1andPR#2.Since GitHub does not recognize that
PR#1andPR#2are already merged, Aviator automatically closes them and applies the GitHub labelmerged-by-mqto represent that the PRs are indeed merged.
See also Separating the merge commits.
Parallel mode
Similar to Sequential mode, parallel mode also considers the stack as a single PR in the queue. In parallel mode:
Aviator creates a batch using the head branch of
PR#3including all the changes ofPR#1andPR#2as well.After the batch passes CI, Aviator changes the base branch of
PR#3and merges it.Since
PR#3is stacked on top ofPR#1andPR#2, merging PR#3 also merges all the changes associated withPR#1andPR#2.As in Sequential mode, Aviator closes
PR#1andPR#2, while applying the GitHub labelmerged-by-mqto represent that the PRs are indeed merged.
See also Separating the merge commits.
Fast forwarding
Fast forwarding mode provides a simpler experience for merging stacked PRs. Since in case of fast-forwarding, we fast-forward the mainline to commits in draft PRs, the CI is already passing. This allows Aviator to merge the PRs individually without GitHub blocking the commits.
In fast-forwarding mode:
When the stack with
PR#3is requested merging, Aviator creates one squash commit for each PR in the stack.After CI passes, the mainline is fast-forwarded to the latest commit in the batch associated with
PR#3, this includes separate commits associated withPR#2andPR#1in the linear history.
Separating the merge commits
By default the Sequential and Parallel modes create a single commit in the mainline for all of the stacked PRs that are queued together. This is because GitHub does not let an app account bypass the branch protection rules. Even when allowed to bypass the rules, GitHub will let the Aviator app only bypass the approval requirement and PR creation requirement, not the CI validation requirement.
Rulesets
This capability of bypassing the CI requirement is now available using GitHub’s Rulesets. Rulesets offer feature parity with the configurations you use in classic branch protection rules and you should be able to migrate all your existing configurations to using Rulesets.
Once migrated to Ruleset, you can add Aviator app in the bypass list.

Configuring separate commits
Once Rulesets are configured and other GitHub branch protection rules are disabled, you can configure Aviator to start creating separate commits for stacked PRs. To do so, set the following in the merge_strategy section of the configuration YAML.
merge_strategy:
use_separate_commits_for_stack: trueFor details, refer to the configuration reference.
If you need assistance in setting up the Rulesets, please contact [email protected].
Setting original PRs as merged [Beta]
When Aviator merges stack PRs, by default the following occurs:
PRs are marked as closed with the label
merged-by-mqPRs do not appear as "merged" in the GitHub UI
The commits are squashed into the main branch using a separate strategy to prevent merge conflicts
GitHub cannot detect that these PRs were actually merged due to the squashing strategy
To workaround this behavior, Aviator has introduced a new mode. In this mode Aviator will force update each PR with the corresponding squash commit while merging the PR. That way, when mainline is forwarded to this commit SHA, GitHub recognizes the PR as merged.
To enable this config, set update_pr_commits_before_stack_merge to true in merge_strategy. Note that this config also requires use_separate_commits_for_stack to be enabled.
merge_strategy:
use_separate_commits_for_stack: true
update_pr_commits_before_stack_merge: trueDetecting stacked PRs without av CLI
If you are creating stacks manually or using a thirdparty tool, you can enable auto-detection of stacked PRs using the config:
merge_rules:
auto_detect_stacks: trueNote that, auto-detection can have some side effects where Aviator might detect PRs in a stack even when they were not intentionally created as stacked. For instance, if you have a PR from a releasebranch to main to backport some changes, meanwhile have a PR from a featureAbranch to releasebranch, the auto-detect will detect this as a stack. To avoid this, you can add releasebranch as one of the base branches in the config.
Last updated
Was this helpful?
