Use this API to manage Git branches.
To change the branch protections configured for a project, use the protected branches API.
List all repository branches
GET /api/v4/projects/{id}/repository/branches
Lists all repository branches from a specified project, sorted alphabetically by name. Search by name, or use regular expressions to find specific branch patterns. Returns detailed information about the branch, including its protection status, merge status, and commit details. This endpoint can be accessed without authentication if the repository is publicly accessible.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
searchQuery | String | Return branches containing the search string.^term to find branches that begin with term,term$ to find branches that end with term |
regexQuery | String | Return branches with names matching an RE2 regular expression.search |
sortQuery | String | Sort results by the specified field and direction Allowed values: name_,updated_,updated_ |
page_Query | String | Name of the branch to start the pagination from. |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | 404 Project Not Found | — |
Create a repository branch
POST /api/v4/projects/{id}/repository/branches
Creates a branch in the repository.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branchRequired | String | Name of the branch |
refRequired | String | Branch name or commit SHA to create the branch from |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Branch already exists | — |
404 | Not Found | — |
Retrieve a repository branch
GET /api/v4/projects/{id}/repository/branches/{branch}
Retrieves a specified project repository branch. This endpoint can be accessed without authentication if the repository is publicly accessible.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | URL- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Project Not Found | — |
Delete a repository branch
DELETE /api/v4/projects/{id}/repository/branches/{branch}
Deletes a specified branch from the repository. If an error occurs, the response includes a message that explains it. Deleting a branch does not completely erase all related data. Some information persists to maintain project history and to support recovery processes.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | URL- |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Branch Not Found | — |
Check if a branch exists
HEAD /api/v4/projects/{id}/repository/branches/{branch}
Checks whether a branch exists in the repository, without returning the branch.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | URL- |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not Found | — |
Protect a single branch
PUT /api/v4/projects/{id}/repository/branches/{branch}/protect
Protects a single branch, or updates its protection if it is already protected. Only users with the Maintainer role can push or merge unless developers_can_push or developers_can_merge is true.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | Name of the branch |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
developers_ | Boolean | If true, |
developers_ | Boolean | If true, |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | 404 Branch Not Found | — |
Unprotect a single branch
PUT /api/v4/projects/{id}/repository/branches/{branch}/unprotect
Removes the protection from a single protected branch.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | Name of the branch |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | 404 Branch Not Found | — |
Delete all merged branches
DELETE /api/v4/projects/{id}/repository/merged_branches
Deletes all branches that are merged into the default branch for a project. Protected branches are not deleted.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
Responses
| Code | Description | Schema |
|---|---|---|
202 | 202 Accepted | — |
400 | Bad Request | — |
404 | 404 Project Not Found | — |
429 | 429 Too Many Requests | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesBranch
| Property | Type | Description |
|---|---|---|
can_ | Boolean | Whether the authenticated user can push to the branch Example: true |
commit | APIEntities | Latest commit on the branch |
default | Boolean | Whether the branch is the default branch of the project Example: true |
developers_ | Boolean | Whether a protected branch rule allows the Developer role to merge to the branch Example: true |
developers_ | Boolean | Whether a protected branch rule allows the Developer role to push to the branch Example: true |
merged | Boolean | Whether the branch is merged into the default branch Example: true |
name | String | Name of the branch Example: master |
protected | Boolean | Whether the branch is protected Example: true |
web_ | String | URL of the branch in the Git Example: https: |
APIEntitiesCommit
| Property | Type | Description |
|---|---|---|
author_ | String | Email address of the commit author Example: john@example. |
author_ | String | Name of the commit author Example: John Smith |
authored_ | String (date- | Date and time when the commit was authored Example: 2012- |
committed_ | String (date- | Date and time when the commit was committed Example: 2012- |
committer_ | String | Email address of the committer Example: jack@example. |
committer_ | String | Name of the committer Example: Jack Smith |
created_ | String (date- | Date and time when the commit was created.committed_Example: 2017- |
extended_ | Object | Git trailers parsed from the commit message, Example: {"Signed- |
id | String | Full SHA of the commit Example: 2695effb5807a22ff3d1 |
message | String | Full commit message Example: Initial commit |
parent_ | Array of strings | SHAs of the parent commits Example: ["2a4b78934375d7f53875 |
short_ | String | Short SHA of the commit Example: 2695effb |
title | String | Title of the commit message Example: Initial commit |
trailers | Object | Git trailers parsed from the commit message. Example: {"Merged- |
web_ | String | URL to view the commit in the Git Example: https: |