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.
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.
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 | Project Not Found | — |
Delete a repository branch
DELETE /api/v4/projects/{id}/repository/branches/{branch}
Deletes a specified branch from the repository.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | Name of the branch |
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}
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
branchPath, | String | Name of the branch |
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
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
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.
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 | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesBranch
| Property | Type | Description |
|---|---|---|
can_ | Boolean | Example:true |
commit | APIEntities | — |
default | Boolean | Example:true |
developers_ | Boolean | Example:true |
developers_ | Boolean | Example:true |
merged | Boolean | Example:true |
name | String | Example:master |
protected | Boolean | Example:true |
web_ | String | Example:https: |
APIEntitiesCommit
| Property | Type | Description |
|---|---|---|
author_ | String | Example:john@example. |
author_ | String | Example:John Smith |
authored_ | String (date- | Example:2012- |
committed_ | String (date- | Example:2012- |
committer_ | String | Example:jack@example. |
committer_ | String | Example:Jack Smith |
created_ | String (date- | Example:2017- |
extended_ | Object | Example:{"Signed- |
id | String | Example:2695effb5807a22ff3d1 |
message | String | Example:Initial commit |
parent_ | Array of strings | Example:["2a4b78934375d7f53875 |
short_ | String | Example:2695effb |
title | String | Example:Initial commit |
trailers | Object | Example:{"Merged- |
web_ | String | Example:https: |