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 | The ID or URL- |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
searchQuery | String | Return list of branches matching the search criteria |
regexQuery | String | Return list of branches matching the regex |
sortQuery | String | Return list of branches sorted by the given field Allowed values: name_,updated_,updated_ |
page_Query | String | Name of branch to start the pagination from |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | 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 | The ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branchRequired | String | The name of the branch |
refRequired | String | Create branch from commit sha or existing branch |
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 | The ID or URL- |
branchPath, | String | The 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 | The ID or URL- |
branchPath, | String | The 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 | The ID or URL- |
branchPath, | String | The 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 | The ID or URL- |
branchPath, | String | The name of the branch |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
developers_ | Boolean | Flag if developers can merge to that branch |
developers_ | Boolean | Flag if developers can push to that branch |
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 | The ID or URL- |
branchPath, | String | The 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 | The 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: |