View as Markdown

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.

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
.mergify.ymlyaml
queue_rules:
- name: default
merge_method: merge

Creates 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.

A A B B A->B C C B->C M M B->M D D C->D D->M _branch0 main _branch0->M A A B B A->B C C B->C M M B->M D D C->D D->M _branch0 main _branch0->M
  • 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

.mergify.ymlyaml
queue_rules:
- name: default
merge_method: squash

Squashes all PR commits into a single commit on the base branch.

A A B B A->B S S B->S C C B->C D D C->D D->S  squashed    into one commit   _branch0 main _branch0->S A A B B A->B S S B->S C C B->C D D C->D D->S  squashed    into one commit   _branch0 main _branch0->S
  • 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 log where one commit = one PR
.mergify.ymlyaml
queue_rules:
- name: default
merge_method: rebase

Replays each PR commit on top of the base branch, creating new commits with new SHAs.

A A B B A->B C C A->C Cp C' B->Cp  replayed with    new SHAs   D D C->D Dp D' Cp->Dp _branch0 main _branch0->Dp A A B B A->B C C A->C Cp C' B->Cp  replayed with    new SHAs   D D C->D Dp D' Cp->Dp _branch0 main _branch0->Dp
  • 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

.mergify.ymlyaml
queue_rules:
- name: default
merge_method: fast-forward

Fast-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.

The 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.

A A B B A->B C C B->C  same SHAs    on base branch   D D C->D _branch0 main _branch0->D A A B B A->B C C B->C  same SHAs    on base branch   D D C->D _branch0 main _branch0->D
  • 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

Mergify 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

  • commit_message_format has 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_retries is 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 both max_checks_retries and merge_queue.max_parallel_checks above 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

Inplace mode, with strictly linear history and preserved commit SHAs:

.mergify.ymlyaml
merge_queue:
max_parallel_checks: 1
queue_rules:
- name: default
merge_method: fast-forward
batch_size: 1
queue_conditions:
- check-success = ci

The 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:

.mergify.ymlyaml
queue_rules:
- name: default
merge_method: fast-forward
batch_size: 5
merge_conditions:
- check-success = ci
.mergify.ymlyaml
queue_rules:
- name: default
merge_method: merge-batch
batch_size: 5
merge_conditions:
- check-success = ci

With 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_format sets the title and body unless they are inherit, 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.

A A B B A->B C1 C1 B->C1 C2 C2 B->C2 D1 D1 B->D1  batch PR   M M B->M C1->D1  merges #42   D2 D2 C2->D2  merges #43   D1->D2 D2->M  merge commit   _branch0 main _branch0->M A A B B A->B C1 C1 B->C1 C2 C2 B->C2 D1 D1 B->D1  batch PR   M M B->M C1->D1  merges #42   D2 D2 C2->D2  merges #43   D1->D2 D2->M  merge commit   _branch0 main _branch0->M
  • 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_account and the base branch’s required status checks let Mergify push

B B M1 M1 B->M1 M2 M2 M1->M2 _branch0 main before _branch0->B _branch1 main after one push _branch1->M2 B B M1 M1 B->M1 M2 M2 M1->M2 _branch0 main before _branch0->B _branch1 main after one push _branch1->M2
Two batches ready at once: one push moves main past both merge commits, so a workflow on push runs once, on M2.

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 request

A 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.

If 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 methods

The 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)
.mergify.ymlyaml
queue_rules:
- name: default
merge_method: merge
update_method: rebase

PRs 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 update
.mergify.ymlyaml
queue_rules:
- name: default
merge_method: rebase
update_method: rebase

PRs 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.

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?