View as Markdown

Mergify Squash Command

Squash the commits of a pull request into one.


The squash command condenses all the changes from a pull request into a single commit. For PRs that come with many incremental commits, it keeps the commit history neat and concise, especially when you wish to merge a pull request without the clutter of multiple individual commits.

B B C C B->C S S B->S D D C->D D->S _branch0 main _branch0->B _branch1 pull request _branch1->S B B C C B->C S S B->S D D C->D D->S _branch0 main _branch0->B _branch1 pull request _branch1->S
Squash replaces the pull request's commits with a single commit carrying all their changes, and force-pushes the branch. Orange is what the command writes.

The squash command is useful for:

  • Clarity and Neatness: Maintaining a clean commit history, especially when numerous commits have only minor changes.

  • Simplified Review: When reviewers prefer seeing the entirety of changes in one commit, making the review process more straightforward.

@Mergifyio squash [<commit message format>]
  • commit message format defines what commit message to use for the squashed commit. Possible values are:

    • all-commits to use the same format as GitHub squashed merge commit (default).

    • first-commit to use the message of the first commit of the pull request.

    • title+body means to use the title and body from the pull request itself as the commit message. The pull request number will be added to end of the title.

Squashing force-pushes the pull request’s head branch, and Mergify does that as a GitHub user rather than as itself. Unless a bot_account is configured, that user is whoever posted the command. That account must have signed in to the Mergify dashboard at least once, and must have write access to the repository unless it is the author of a pull request opened from a fork. When one of those is missing, the command fails with Mergify can't impersonate.

That account cannot be a bot: Mergify cannot impersonate an account owned by another GitHub App. When a GitHub App posts the command, the fallback account is that bot, and the command fails. Set bot_account to a user account so the command still runs.

Mergify also checks which repository that head branch lives in, and writes the branch only when it belongs to your repository or to a fork of it. See the update action for the cases it refuses.

Was this page helpful?