- List repository branches
- Get single repository branch
- Protect repository branch
- Unprotect repository branch
- Create repository branch
- Delete repository branch
- Delete merged branches
Branches API
This API operates on repository branches.
Tip:
See also Protected branches API.
List repository branches
Get a list of repository branches from a project, sorted by name alphabetically.
Note:
This endpoint can be accessed without authentication if the repository is publicly accessible.
GET /projects/:id/repository/branches
Parameters:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer/string | yes | ID or URL-encoded path of the project owned by the authenticated user. |
search |
string | no | Return list of branches containing the search string. You can use ^term and term$ to find branches that begin and end with term respectively. |
Example request:
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/5/repository/branches
Example response:
[
{
"name": "master",
"merged": false,
"protected": true,
"default": true,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
}
},
...
]
Get single repository branch
Get a single project repository branch.
Note:
This endpoint can be accessed without authentication if the repository is publicly accessible.
GET /projects/:id/repository/branches/:branch
Parameters:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer/string | yes | ID or URL-encoded path of the project owned by the authenticated user. |
branch |
string | yes | Name of the branch. |
Example request:
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/5/repository/branches/master
Example response:
{
"name": "master",
"merged": false,
"protected": true,
"default": true,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
}
}
Protect repository branch
See POST /projects/:id/protected_branches
for
information on protecting repository branches.
Unprotect repository branch
See DELETE /projects/:id/protected_branches/:name
for information on unprotecting repository branches.
Create repository branch
Create a new branch in the repository.
POST /projects/:id/repository/branches
Parameters:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer | yes | ID or URL-encoded path of the project owned by the authenticated user. |
branch |
string | yes | Name of the branch. |
ref |
string | yes | Branch name or commit SHA to create branch from. |
Example request:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/5/repository/branches?branch=newbranch&ref=master
Example response:
{
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
},
"name": "newbranch",
"merged": false,
"protected": false,
"default": false,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true
}
Delete repository branch
Delete a branch from the repository.
Note:
In the case of an error, an explanation message is provided.
DELETE /projects/:id/repository/branches/:branch
Parameters:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer/string | yes | ID or URL-encoded path of the project owned by the authenticated user. |
branch |
string | yes | Name of the branch. |
Example request:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/5/repository/branches/newbranch
Delete merged branches
Will delete all branches that are merged into the project’s default branch.
Note:
Protected branches will not be deleted as part of this operation.
DELETE /projects/:id/repository/merged_branches
Parameters:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer/string | yes | ID or URL-encoded path of the project owned by the authenticated user. |
Example request:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/5/repository/merged_branches
Help and feedback
If there's something you don't like about this feature
To propose functionality that GitLab does not yet offer
To further help GitLab in shaping new features
If you didn't find what you were looking for
If you want help with something very specific to your use case, and can use some community support
POST ON GITLAB FORUM
If you have problems setting up or using this feature (depending on your GitLab subscription)
REQUEST SUPPORT
To view all GitLab tiers and features or to upgrade
If you want to try all features available in GitLab.com
If you want to try all features available in GitLab self-managed
If you spot an error or a need for improvement and would like to fix it yourself in a merge request
EDIT THIS PAGE
If you would like to suggest an improvement to this doc