---
title: Squash
description: 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](/workflow/actions/update#fork-pull-requests) apply here too.

## Parameters

| Key name | Value type | Default | Description |
| --- | --- | --- | --- |
| `bot_account` | simple-template or null | `null` | Mergify can impersonate a GitHub user to squash a pull request. If no `bot_account` is set, Mergify will squash the pull request itself |
| `commit_message` | `all-commits` or `first-commit` or `title+body` | `"all-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. |

## Examples

### Squash on Label

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:

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