---
title: Rebase
description: Rebase the pull request on top of its base branch.
---

The `rebase` action makes Mergify rebase the pull request on top of its base
branch. This is useful when you want to ensure that your pull request is always
up-to-date with the latest changes from the base branch.

:::note
  You do not need to use this action if you use the [merge
  queue](/merge-queue). The merge queue automatically updates the pull requests
  it processes as necessary, making sure they are tested with up-to-date code
  before being merged.
:::

:::caution
  This action does not rebase a pull request opened from a fork. It always
  rebases as a GitHub user, and GitHub refuses an OAuth token on its rebase API
  for a fork, so doing it would mean impersonating that user to force-push the
  contributor's branch. The action reports that the pull request was opened
  from a fork and cannot be rebased, and does nothing, whether or not
  [`bot_account`](/configuration/data-types#bot-account) is set.

  Use the [`update` action](/workflow/actions/update) on those instead: it
  merges the base branch into the pull request, and impersonates nobody unless
  you set its own `bot_account`. It only acts when the pull request is behind
  its base branch, so a branch that needs a linear history has to be rebased by
  its author.
:::

## Rebase Requirements

Whatever your conditions are, Mergify adds its own requirements before running
the action. A pull request is rebased only when it is open, has no conflict, is
not in a merge queue
([`queue-position = -1`](/configuration/conditions#attributes-list)), and is
either behind its base branch (`#commits-behind > 0`) or does not have a linear
history (`-linear-history`).

A pull request opened from another repository whose head branch Mergify cannot
write at all, such as one whose fork has been deleted, is refused for that
reason rather than the one above, and the check run says so. [The `update`
action](/workflow/actions/update#fork-pull-requests) covers those cases, which
refuse `update` too.

## Impersonation

Rebasing always acts as a GitHub user. With no `bot_account` set, that user is
the pull request author, or whoever posted the [`@mergifyio rebase`
command](/commands/rebase) when a command triggered the rebase. The account must
have signed in to the [Mergify dashboard](https://dashboard.mergify.com) 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 rebase those.

## Parameters

| Key name | Value type | Default | Description |
| --- | --- | --- | --- |
| `bot_account` | simple-template or null | `null` | To rebase, Mergify needs to impersonate a GitHub user. You can specify the account to use with this option. If no `bot_account` is set, Mergify picks the pull request author, or the user who sent the `@mergifyio rebase` 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 rebase 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.  **Warning:** A pull request coming from a fork cannot be rebased, whether or not this option is set: rebasing one means impersonating a GitHub user to force-push the contributor's branch. Use the `update` action or the `@mergifyio update` command on those -- except where Mergify cannot write the head branch at all, such as a deleted fork, where `update` is refused too and the check run says what is wrong. |

## Examples

### Rebase on Label

Rebase a pull request when it gets the `ready-to-merge` label.

```yaml
pull_request_rules:
  - name: rebase when ready to merge
    conditions:
      - label = ready-to-merge
    actions:
      rebase:
```
