View as Markdown

Sharing Configuration

Learn how to share and reuse configuration pieces in your configuration.


In Mergify, you can use features like YAML anchors and aliases, the shared key, and the extends key to reduce redundancy and keep your configuration consistent.

YAML anchors (&) and aliases (*) are supported in the configuration file. These allow you to reuse configuration sections. For example, you can create a list of continuous integration checks and use it in multiple sections:

.mergify.ymlyaml
queue_rules:
- name: hotfix
queue_conditions:
- and: &CheckRuns
- check-success = linters
- check-success = unit
- check-success = functional
- check-success = e2e
- check-success = docker
- name: default
queue_conditions:
- and: *CheckRuns
- schedule = Mon-Fri 09:00-17:30[Europe/Paris]

Sharing configuration sections

Section titled Sharing configuration sections

You can store anything in the shared key. Its main purpose is to provide a place to put redundant YAML anchors:

.mergify.ymlyaml
shared:
my_ci: &common_checks
- check-success = ci-one
- check-success = ci-two
queue_rules:
- name: hotfix
queue_conditions:
- and: *common_checks
- name: default
queue_conditions:
- and: *common_checks
- schedule = Mon-Fri 09:00-17:30[Europe/Paris]

Mergify lets you extend your configuration file by including the configuration from another repository. This feature is useful when you want to share and reuse configuration rules across multiple repositories, helping maintain consistency and reduce duplication.

To extend a configuration file, use the extends keyword at the top level of your configuration file and specify the repository name from which you want to include the configuration. The value is the repository name on its own, not owner/repo: the repository is looked up in the same organization.

.mergify.ymlyaml
extends: shared-config

The configuration from the source repository is merged into the one in the current repository, whose rules come first in every rule section, before the ones the extended configuration adds. Here’s an example:

.mergify.ymlyaml
extends: shared-config
pull_request_rules:
- name: additional rule specific to this repository
conditions:
- base = main
actions:
label:
add:
- repository-specific

Was this page helpful?