2014-09-02 18:07:02 +05:30
|
|
|
# Branches
|
|
|
|
|
|
|
|
## List repository branches
|
|
|
|
|
|
|
|
Get a list of repository branches from a project, sorted by name alphabetically.
|
|
|
|
|
|
|
|
```
|
|
|
|
GET /projects/:id/repository/branches
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
```bash
|
|
|
|
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/repository/branches
|
|
|
|
```
|
|
|
|
|
|
|
|
Example response:
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
[
|
|
|
|
{
|
2016-04-02 18:10:28 +05:30
|
|
|
"name": "master",
|
|
|
|
"protected": true,
|
2014-09-02 18:07:02 +05:30
|
|
|
"commit": {
|
2015-04-26 12:48:37 +05:30
|
|
|
"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",
|
2014-09-02 18:07:02 +05:30
|
|
|
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
|
|
|
|
"message": "add projects API",
|
2015-04-26 12:48:37 +05:30
|
|
|
"parent_ids": [
|
|
|
|
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
|
|
|
|
]
|
2016-04-02 18:10:28 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
...
|
2014-09-02 18:07:02 +05:30
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
## Get single repository branch
|
|
|
|
|
|
|
|
Get a single project repository branch.
|
|
|
|
|
|
|
|
```
|
|
|
|
GET /projects/:id/repository/branches/:branch
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
|
|
|
| `branch` | string | yes | The name of the branch |
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
```bash
|
|
|
|
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/repository/branches/master
|
|
|
|
```
|
|
|
|
|
|
|
|
Example response:
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2016-04-02 18:10:28 +05:30
|
|
|
"name": "master",
|
|
|
|
"protected": true,
|
2014-09-02 18:07:02 +05:30
|
|
|
"commit": {
|
2015-04-26 12:48:37 +05:30
|
|
|
"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",
|
2014-09-02 18:07:02 +05:30
|
|
|
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
|
|
|
|
"message": "add projects API",
|
2015-04-26 12:48:37 +05:30
|
|
|
"parent_ids": [
|
|
|
|
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
|
|
|
|
]
|
2016-04-02 18:10:28 +05:30
|
|
|
}
|
2014-09-02 18:07:02 +05:30
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Protect repository branch
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
Protects a single project repository branch. This is an idempotent function,
|
|
|
|
protecting an already protected repository branch still returns a `200 OK`
|
|
|
|
status code.
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
PUT /projects/:id/repository/branches/:branch/protect
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
```bash
|
|
|
|
curl -X PUT -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/repository/branches/master/protect
|
|
|
|
```
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
|
|
|
| `branch` | string | yes | The name of the branch |
|
|
|
|
|
|
|
|
Example response:
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"commit": {
|
2015-04-26 12:48:37 +05:30
|
|
|
"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",
|
2014-09-02 18:07:02 +05:30
|
|
|
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
|
|
|
|
"message": "add projects API",
|
2015-04-26 12:48:37 +05:30
|
|
|
"parent_ids": [
|
|
|
|
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
|
|
|
|
]
|
2014-09-02 18:07:02 +05:30
|
|
|
},
|
2015-04-26 12:48:37 +05:30
|
|
|
"name": "master",
|
2014-09-02 18:07:02 +05:30
|
|
|
"protected": true
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Unprotect repository branch
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
Unprotects a single project repository branch. This is an idempotent function,
|
|
|
|
unprotecting an already unprotected repository branch still returns a `200 OK`
|
|
|
|
status code.
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
PUT /projects/:id/repository/branches/:branch/unprotect
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
```bash
|
|
|
|
curl -X PUT -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/repository/branches/master/unprotect
|
|
|
|
```
|
|
|
|
|
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
|
|
|
| `branch` | string | yes | The name of the branch |
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
Example response:
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"commit": {
|
2015-04-26 12:48:37 +05:30
|
|
|
"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",
|
2014-09-02 18:07:02 +05:30
|
|
|
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
|
|
|
|
"message": "add projects API",
|
2015-04-26 12:48:37 +05:30
|
|
|
"parent_ids": [
|
|
|
|
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
|
|
|
|
]
|
2014-09-02 18:07:02 +05:30
|
|
|
},
|
2015-04-26 12:48:37 +05:30
|
|
|
"name": "master",
|
2014-09-02 18:07:02 +05:30
|
|
|
"protected": false
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Create repository branch
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /projects/:id/repository/branches
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
|
|
|
| `branch_name` | string | yes | The name of the branch |
|
|
|
|
| `ref` | string | yes | The branch name or commit SHA to create branch from |
|
|
|
|
|
|
|
|
```bash
|
|
|
|
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/repository/branches?branch_name=newbranch&ref=master"
|
|
|
|
```
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
Example response:
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"commit": {
|
|
|
|
"author_email": "john@example.com",
|
2015-04-26 12:48:37 +05:30
|
|
|
"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",
|
|
|
|
"message": "add projects API",
|
|
|
|
"parent_ids": [
|
|
|
|
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
|
|
|
|
]
|
2014-09-02 18:07:02 +05:30
|
|
|
},
|
2016-04-02 18:10:28 +05:30
|
|
|
"name": "newbranch",
|
2014-09-02 18:07:02 +05:30
|
|
|
"protected": false
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
It returns `200` if it succeeds or `400` if failed with an error message
|
|
|
|
explaining the reason.
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
## Delete repository branch
|
|
|
|
|
|
|
|
```
|
|
|
|
DELETE /projects/:id/repository/branches/:branch
|
|
|
|
```
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
| Attribute | Type | Required | Description |
|
|
|
|
| --------- | ---- | -------- | ----------- |
|
|
|
|
| `id` | integer | yes | The ID of a project |
|
|
|
|
| `branch` | string | yes | The name of the branch |
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
It returns `200` if it succeeds, `404` if the branch to be deleted does not exist
|
|
|
|
or `400` for other reasons. In case of an error, an explaining message is provided.
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
```bash
|
|
|
|
curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/repository/branches/newbranch"
|
|
|
|
```
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
Example response:
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2016-04-02 18:10:28 +05:30
|
|
|
"branch_name": "newbranch"
|
2015-04-26 12:48:37 +05:30
|
|
|
}
|
|
|
|
```
|