doc/user/project/repository/branches/branch_rules.md
{{< details >}}
{{< /details >}}
GitLab provides multiple methods to protect individual branches. These methods ensure your branches receive oversight and quality checks from their creation to their deletion:
CODEOWNERS file can be pushed directly to the branch.You can manage your branches:
{{< history >}}
branch_rules removed.{{< /history >}}
The branch rules overview page shows all branches with any configured protections, and their protection methods:
Prerequisites:
To view the branch rules overview list:
To view branch rules and protections for a single branch:
{{< history >}}
add_branch_rules. Disabled by default.add_branch_rules renamed to edit_branch_rules in GitLab 16.11. Disabled by default.edit_branch_rules removed.{{< /history >}}
Prerequisites:
To create a branch rule:
*.[!note] Not available for
all branches.
To add protections to a new branch:
{{< details >}}
{{< /details >}}
[!note] Not available for
all branches.
Prerequisites:
To add a merge request approval rule:
Enter a Rule name.
In Required number of approvals, enter a value (0-100).
A value of 0 makes the rule optional, and any number greater than 0 creates a required rule.
The maximum number of required approvals is 100.
Select users or groups that are eligible to approve.
GitLab suggests approvers based on previous authors of the files changed by the merge request.
For additional information, see approval rules.
{{< details >}}
{{< /details >}}
{{< history >}}
branch_rule_squash_settings. Disabled by default.branch_rule_squash_settings removed.{{< /history >}}
Prerequisites:
To edit a squash option:
From the branch rule details page, go to the Squash commits when merging section.
Select Edit.
Select one of the following options:
Select Save changes.
{{< details >}}
{{< /details >}}
{{< history >}}
edit_branch_rules. Disabled by default.edit_branch_rules removed.{{< /history >}}
[!note] Not available for
all protected branches.
To add a status check service:
From the branch rule details page, go to the Status checks section.
Select Add status check.
Enter the Service name.
In the API to check field, enter the URL.
You should use an HTTPS URL to protect your merge request data in transit.
For more information, see external status checks.
{{< history >}}
add_branch_rules. Disabled by default.add_branch_rules renamed to edit_branch_rules in GitLab 16.11. Disabled by default.edit_branch_rules removed.{{< /history >}}
Prerequisites:
To edit a branch rule target:
For information about branch protection controls, see Protected branches.
[!note] Not available for
all branches.
{{< history >}}
add_branch_rules. Disabled by default.add_branch_rules renamed to edit_branch_rules in GitLab 16.11. Disabled by default.edit_branch_rules removed.{{< /history >}}
Prerequisites:
To delete a branch rule:
[!note] Deleting a branch rule is not available for rules targeting
all branches.