# Set up merge rules

> Set the rules for merging branches.

Edit the `mergerules.conf` file in your `server` directory to configure your merge rules.

> **Note:**
>
> You can also set up merge rules in your [webadmin server administration console](../../webadmin/access-webadmin).

The mergerules.conf file is a JSON file that contains your merge rules. To add a merge rule, you need to place the rule inside an array:

```text
[{
    "enabled": true,
    "repositories": "code*",

    "rule": "only_allow_merges_if_reviewed",
    "to":
    {
        "branchNames": ["main"],
        "branchesWithAttribute": [
            {
                "attribute": "merge_only_reviewed",
                "value": "enabled"
            }
        ]
    },
    "from":
    {
        "branchNames": ["scm*"],
        "branchesWithAttribute": [
            {
                "attribute": "task",
            }
        ]
    }
}]
```

You can use the following parameters to define your merge rules:

| Parameter      | Description                                                                                                                     |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `enabled`      | Enter `true` to enable the merge rule, and `false` to disable the merge rule.                                                   |
| `repositories` | Use patterns to match any repositories you want the merge rule to apply to.                                                     |
| `rule`         | Specify the merge rule to use. To find the available merge rules, refer to the page on [types of merge rules](./rule-types.md). |
| `to`           | Specify any destination branches you want to apply the merge rule to.                                                           |
| `from`         | Specify any source branches you want to apply the merge rule to.                                                                |

You can filter the branches that you apply the merge rule to. Use the following parameters under either `to` or `from`:

| Parameter               | Description                                                                                                                   |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `branchNames`           | Use this key to specify the branch names or that you want to apply the merge rule to. Use an `*` to represent any sub string. |
| `brancheswithAttribute` | Use this key to filter branches by attribute. Specify the `attribute` name and, if necessary, a `value`.                      |
|     `attribute`         | If you filter branches by attribute, use this key to specify which attribute to use.                                          |
|     `value`             | If you filter branches by attribute, you can specify a value for the attribute.                                               |
