View as Markdown

Squash

Squash commits in the pull request.


The squash action instructs Mergify to squash all commits from a pull request into one.

When you add this action to a rule, Mergify will squash all the commits from the pull request into one commit, making the history of your project cleaner and easier to read.

Squashing writes the pull request’s head branch, so the restrictions on writing a fork’s branch apply here too.

Squashing force-pushes the head branch, and Mergify does that as a GitHub user rather than as itself. With no bot_account set, that user is the pull request author, or whoever posted the @mergifyio squash command when a command triggered the squash. The account must have signed in to the Mergify dashboard at least once.

That account cannot be a bot: Mergify cannot impersonate an account owned by another GitHub App. The action fails whenever the account it falls back to is one, whether a GitHub App opened the pull request, such as a dependency update bot, or posted the command. Set bot_account to a user account to squash those.

bot_account#Bot account or null·defaultnull

Mergify can impersonate a GitHub user to squash a pull request. If no bot_account is set, Mergify picks the pull request author, or the user who sent the @mergifyio squash command. The user account must have already been logged in Mergify dashboard once.

Warning: Because of GitHub's security restrictions, Mergify cannot impersonate an account owned by another GitHub App. A squash therefore fails whenever the account it falls back to is a bot, either because the pull request was opened by one or because one sent the command, unless bot_account names a user account.

commit_message#all-commits, first-commit or title+body·defaultall-commits

Defines what commit message to use for the squashed commit if no commit message is defined in the pull request body. Possible values are:

  • all-commits to use the same format as GitHub squashed merge commit.
  • 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.

In this example, whenever there’s a label to-squash added, any new commits pushed to the branch will be squashed into a single commit:

pull_request_rules:
- name: automatic squash of pull requests
conditions:
- label = to-squash
actions:
squash:

Was this page helpful?