protect_branch
Set branch protection rules to control who can push, merge, or unprotect, and enable force-push or code-owner approvals. Define clear permissions to safeguard critical branches.
Instructions
Protect a repository branch (set push/merge/unprotect access levels). Use this to create or update protection rules for a branch or wildcard; use get_protected_branch to inspect existing rules first. The operation changes who may push, merge, or unprotect, may enable force-push or code-owner settings, requires maintainer-level permission, and returns the protection rule or a validation/permission error.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Deprecated alias for branch_name; prefer branch_name for consistency | |
| project_id | No | Project ID or complete URL-encoded path to project | |
| branch_name | Yes | Branch name or wildcard pattern to protect | |
| allow_force_push | No | Allow force push to the protected branch. Default: false | |
| push_access_level | No | Access level for pushing (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted. | |
| merge_access_level | No | Access level for merging (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted. | |
| unprotect_access_level | No | Access level for unprotecting (0=No access, 30=Developer, 40=Maintainer, 60=Admin). GitLab default applies when omitted. | |
| code_owner_approval_required | No | Require code owner approval before merging (PREMIUM). Default: false |