Group-level protected branches API
- Tier: Premium, Ultimate
- Offering: GitLab Self-Managed
Use this API to manage protected branch settings that are inherited by all projects in a group. Group protected branches only support valid access levels and, on GitLab Ultimate, custom roles. Individual users and groups cannot be specified.
Protected branch settings for groups are restricted to top-level groups only.
Valid access levels
The access levels are defined in the ProtectedRefAccess.allowed_access_levels method.
These levels are recognized:
0 => No access
30 => Developer access
40 => Maintainer access
60 => Admin accessList protected branches
Gets a list of protected branches from a group. If a wildcard is set, it is returned instead of the exact name of the branches that match that wildcard.
GET /groups/:id/protected_branches| Attribute | Type | Required | Description |
|---|---|---|---|
id | integer or string | yes | The ID or URL-encoded path of the group. |
search | string | no | Name or part of the name of protected branches to be searched for. |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches"Example response:
[
{
"id": 1,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
{
"id": 1,
"name": "release/*",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
...
]Get a single protected branch or wildcard protected branch
Gets a single protected branch or wildcard protected branch.
GET /groups/:id/protected_branches/:name| Attribute | Type | Required | Description |
|---|---|---|---|
id | integer or string | yes | The ID or URL-encoded path of the group. |
name | string | yes | The name of the branch or wildcard. |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/main"Example response:
{
"id": 1,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}Protect repository branches
Protects a single repository branch using a wildcard protected branch.