View as Markdown

Copy

Copy a pull request to another branch.


The copy action enables you to automatically create a copy of a pull request. When the conditions you specify are met, Mergify opens a new pull request against each destination branch you configure.

Note that in case of a conflict during the copy, Mergify will create a pull request with the conflict; you will have to resolve it manually. You can change this behaviour using the ignore_conflicts option.

Mergify opens each copy from a head branch named mergify/copy/<destination-branch>/pr-<original-number>, with the destination branch as its base.

Whatever your conditions are, Mergify adds its own requirement before running the action: a pull request is copied only once it is free of conflict with its own base branch. You do not need a -conflict condition of your own, and a rule whose conditions match while the pull request is in conflict waits for the conflict to clear instead of running. Unlike backport, copy does not require the pull request to be merged.

The requirement applies to the pull request’s own base branch, not to the branches you copy to. A conflict with a destination branch is the kind ignore_conflicts controls, and it does not hold the action back.

The copy action takes a list of branches to which the changes from the pull request will be copied. The branch names should be specified as strings.

regexes picks destination branches by pattern instead of naming each one. Patterns are matched against the branches that exist in the repository, and each one is anchored at the start of a branch name only, so release-1 also matches release-10. Setting both branches and regexes copies to the branches you named plus the branches your patterns matched.

Mergify reads at most 1,000 of the repository’s branches to match regexes. In a repository with more than 1,000 branches, the action fails with “Too many branches to match regexes against” and copies to none of the branches, not even the ones listed in branches. The other rules on the pull request keep running. In a repository that size, list the destination branches in branches instead.

Mergify skips any login ending in [bot] when resolving assignees, so a rule that assigns {{ author }} leaves the copy unassigned if a bot opened the original pull request.

assigneeslist of Assignee#

Users to assign the newly created pull request to. Accepts a GitHub login, or {{ author }} (the original pull request author) or {{ merged_by }} (the user who merged it).

bodyBody template·default#
|
  {{ body }}<hr>This is an automatic copy of pull request #{{number}} done by [Mergify](https://mergify.com).

The pull request's body.

bot_accountBot account or null·defaultnull#

Mergify can impersonate a GitHub user to copy a pull request. If no bot_account is set, Mergify copies the pull request itself. The user account needs write access to the repository.

brancheslist of Branch Name#

The list of branches the pull request should be copied to.

ignore_conflictsboolean·defaulttrue#

Whether to create the pull requests even if there are conflicts when cherry-picking the commits.

label_conflictsstring·defaultconflicts#

The label to add to the created pull request if it has conflicts and ignore_conflicts is set to true.

labelslist of string#

The list of labels to add to the created pull requests.

merge_conflict_stylemerge or diff3·defaultmerge#

Style used by git when displaying merge conflicts

regexeslist of #

The list of regexes to find branches the pull request should be copied to. They are matched against the repository's branches, of which Mergify reads at most 1000: in a repository with more than 1000 branches, the action fails.

report_modelist of Report Mode·default- check#

Reporting modes for the action's result. Check will create a check on the pull request, and comment will post a comment on the pull request.

titleTitle template·default"{{ title }} (copy #{{ number }})"#

The pull request's title.

Mergify cannot copy a pull request that contains a merge commit, such as when you merge a teammate’s branch into yours. Merges of the base branch into your pull request (for example, Merge branch 'main') are an exception and don’t block the copy.

To avoid this, rebase your pull request or squash its commits so its history stays linear.

Below is an example of how to use the copy action:

pull_request_rules:
- name: copy patches to the prod branch
conditions:
- label = copy-to-prod
actions:
copy:
branches:
- prod

Was this page helpful?