Merge Strategies
Choose how pull requests are merged into your base branch and control the shape of your git history.
The merge_method option in your queue rules controls how Mergify merges pull
requests into your base branch. Each method produces a different git history
shape, with trade-offs between linearity, SHA preservation, and throughput.
Merge methods at a glance
Section titled Merge methods at a glance| Method | History | Commits on base branch | SHAs preserved | Queue parallelism |
|---|---|---|---|---|
merge |
Non-linear | Original commits + merge commit | Yes | Full |
squash |
Linear | 1 new commit per PR | No | Full |
rebase |
Linear | Recreated copies of each commit | No | Full |
fast-forward |
Linear | Original commits moved to base | Yes | Serial only |
merge-batch |
Non-linear | Original commits + 1 merge commit per PR + 1 per batch | Yes | Full |
Merge
Section titled Mergequeue_rules: - name: default merge_method: mergeCreates a merge commit joining the PR branch into the base branch. This is the
default GitHub merge behavior. When you leave merge_method unset, Mergify uses
the first method your repository allows, so a repository that disallows merge
commits falls back to squash or rebase instead.
-
History: non-linear; the PR branch and base branch are visible as separate lines in
git log --graph -
Merge commits: yes; each PR produces a merge commit on the base branch
-
SHAs preserved: yes; original PR commits keep their SHAs
-
Use case: most teams; simplest setup with no constraints on parallelism or batching
Squash
Section titled Squashqueue_rules: - name: default merge_method: squashSquashes all PR commits into a single commit on the base branch.
- History: linear; one commit per PR on the base branch
- Merge commits: no
- SHAs preserved: no; a new commit is created
- Use case: teams that want a clean
git logwhere one commit = one PR
Rebase
Section titled Rebasequeue_rules: - name: default merge_method: rebaseReplays each PR commit on top of the base branch, creating new commits with new SHAs.
-
History: linear; no merge commits, individual commits are preserved
-
Merge commits: no
-
SHAs preserved: no; commits are recreated with new SHAs, so the PR branch ref won’t match the base branch
-
Use case: teams that want linear history with individual commits visible, but don’t need SHA preservation
Fast-forward
Section titled Fast-forwardqueue_rules: - name: default merge_method: fast-forwardFast-forward merging advances the base branch ref directly to the tested commit(s), so a commit pushed to a pull request as it lands is left out. The behavior differs between inplace and batch-PR mode.
Inplace mode
Section titled Inplace modeThe PR is rebased on top of the base branch, CI runs on the PR itself, and the base branch ref is fast-forwarded to the PR’s head commit.
In this mode, update_method must be set to rebase (the default). If a
rebase update occurs, the commit SHAs on the PR will change; what fast-forward
preserves are the SHAs of the PR branch at merge time.
-
History: strictly linear; commits sit directly on the base branch
-
Merge commits: none
-
SHAs preserved: yes; the exact same commit SHAs from the PR appear on the base branch
Batch-PR mode
Section titled Batch-PR modeMergify creates a batch PR that combines the queued pull requests, runs CI on that batch, and then fast-forwards the base branch to the batch PR’s head commit.
-
History: linear at the base-branch level, but individual merge commits from combining PRs may appear
-
Merge commits: possible; each is written as described under Merge Batch
-
SHAs preserved: the final merged result is the exact SHA tested by CI
Constraints
Section titled Constraints-
commit_message_formathas no effect when checking in place: fast-forward preserves the original commits, so custom commit messages are not applicable. In batch-PR mode, it sets the message of the commit that merges each PR into the batch branch -
Parallel and isolated modes are not supported: both merge batches independently of each other, which fast-forward cannot do. Mergify rejects a queue rule that combines them
-
max_checks_retriesis not supported with parallel checks: a retry checks the batch again on a new batch PR, so the batches already checked on top of the failed one can no longer be fast-forwarded once it merges. Mergify rejects a configuration that sets bothmax_checks_retriesandmerge_queue.max_parallel_checksabove 1 on a fast-forward queue -
Use case: teams and OSS projects that care about commit identity and want the exact CI-tested code on their base branch
Examples
Section titled ExamplesInplace mode, with strictly linear history and preserved commit SHAs:
merge_queue: max_parallel_checks: 1
queue_rules: - name: default merge_method: fast-forward batch_size: 1 queue_conditions: - check-success = ciThe CI check sits in queue_conditions rather than merge_conditions on purpose:
a queue with separate merge_conditions is a two-step
CI queue, and Mergify runs its checks on a batch pull
request instead of in place. See In-place checks (no batch
PRs) for the full list of
conditions a queue has to meet to check in place.
Batch-PR mode, combining batching with fast-forward merge:
queue_rules: - name: default merge_method: fast-forward batch_size: 5 merge_conditions: - check-success = ciMerge batch
Section titled Merge batchqueue_rules: - name: default merge_method: merge-batch batch_size: 5 merge_conditions: - check-success = ciWith merge-batch, the batch pull request itself lands on the base branch, as a
merge commit that says what the batch brought in, instead of the original pull
requests one by one. A commit pushed to one of them as the batch
lands is left out. The merge commit names up
to five in its title. For #42, #43 and #44, it reads:
Merge #42, #43, #44: Fix the login redirect (+2 more)
- #42 Fix the login redirect (octocat)- #43 Retry failed uploads (hubot)- #44 Raise the cache size (monalisa)Inside the batch branch, each pull request is merged by a commit of its own, which lands on the base branch with the batch and is the pull request’s merge commit on GitHub. Mergify writes its message as if that pull request were merged on its own:
-
the queue rule’s
commit_message_formatsets the title and body unless they areinherit, and appends the trailers -
whatever it leaves to the repository (all of it, when the rule has no
commit_message_format) follows your repository’s merge commit settings on GitHub. With the GitHub defaults, the commit for pull request #42 reads:Merge pull request #42 from octo-org/fix-login Fix the login redirect
Because CI runs on the batch branch, a [skip ci]-style marker or a
skip-checks: true trailer coming from a pull request is put in parentheses,
so it does not skip the batch’s CI.
-
History: non-linear
-
Merge commits: yes; one per batch on the base branch, plus one per PR inside the batch branch
-
SHAs preserved: yes; each pull request’s head is merged into the batch branch, not copied
-
Batches: always, even for one pull request
-
Use case: teams that want one merge commit, and one deployment, per batch
Mergify pushes the merge commits itself instead of having GitHub merge each batch PR:
-
In any mode, for batches tested on top of each other and ready at once
-
In parallel and isolated modes, for every ready batch, when the queue rule sets no
merge_bot_accountand the base branch’s required status checks let Mergify push
A pushed batch leaves the same commits as a merged one, with two differences:
-
Committed by Mergify, not GitHub, and authored by Mergify even under a
merge_bot_account -
The batch PR is merged as a draft
Pushing to a queued pull request
Section titled Pushing to a queued pull requestA push takes a pull request out of the
queue, and
its batch does not land. With fast-forward and merge-batch, one that arrives
as the batch lands can be too late: the base branch gets the commit CI passed
on, without the new one, and Mergify reports the pull request as merged.
Depending on when the push arrived, GitHub shows it:
- Open, at the new commit: queue it again
- Merged, at the old commit: open another pull request for the new one
With the other methods, GitHub refuses to merge a head that moved.
Editing the batch branch
Section titled Editing the batch branchIf anything other than Mergify pushes a commit to the branch of a batch PR, Mergify dequeues the pull requests embarked in it and reports the edit as a failure. Push that commit to the pull requests themselves.
Combining merge and update methods
Section titled Combining merge and update methodsThe update_method option controls how Mergify updates PR branches when they
fall behind the base branch. Combining merge_method with update_method
gives you additional control over your history shape.
Semi-linear history (rebase + merge commit)
Section titled Semi-linear history (rebase + merge commit)queue_rules: - name: default merge_method: merge update_method: rebasePRs are rebased on top of the base branch before being merged with a merge commit. This produces a history where individual commits are linear, but each PR is wrapped in a merge commit that marks the PR boundary.
- Use case: teams that want linear commits but also want merge commits as
PR boundary markers in
git log --graph
Linear history via rebase update
Section titled Linear history via rebase updatequeue_rules: - name: default merge_method: rebase update_method: rebasePRs are rebased to stay current, then rebased again at merge time. This produces a fully linear history with no merge commits, though SHAs will differ from the original PR branch.
Choosing the right strategy
Section titled Choosing the right strategy| I want… | merge |
squash |
rebase |
fast-forward |
merge-batch |
|---|---|---|---|---|---|
| Linear history | ✔ | ✔ | ✔ | ||
| Preserved commit SHAs | ✔ | ✔ | ✔ | ||
| One commit per PR | ✔ | ||||
| One merge commit per batch on the base branch | ✔ | ||||
| Individual PR commits visible | ✔ | ✔ | ✔ | ✔ | |
See PR boundaries in git log |
✔ | ✔ | |||
| Batches and parallel checks | ✔ | ✔ | ✔ | ✔ | |
| Single deployment per batch | ✔ | ✔ |
Was this page helpful?
Thanks for your feedback!