Creating a Branch
Function
This API is used to create a branch in a specified repository based on the repository ID.
URI
POST /v2/repositories/{repository_id}/branches
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
repository_id |
Yes |
String |
Explanation: Repository short ID. Constraints: Mandatory Range: 0–2147483647 Default value: None |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Explanation: User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. Constraints: Mandatory Range: 1–100,000 characters. Default value: None |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
branch_name |
Yes |
String |
Explanation: Branch name. Constraints: Mandatory Range: Minimum length: 1 Maximum length: 200 Default value: None |
ref |
Yes |
String |
Explanation: Source branch name. Constraints: Mandatory Range: Minimum length: 1 Maximum length: 200 Default value: None |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
error |
Error object |
Explanation: Response error code. |
result |
AddProtectResponse object |
Explanation: Response result. |
status |
String |
Explanation: Response status of the API. Range:
|
Parameter |
Type |
Description |
---|---|---|
code |
String |
Explanation: Error code. Range: Max. 100 characters in the error code format. |
message |
String |
Explanation: Error message. Range: None |
Parameter |
Type |
Description |
---|---|---|
name |
String |
Explanation: Branch name. |
commit |
CommitRepoV2 object |
Explanation: Commit message. |
protected |
Boolean |
Explanation: Whether to protect it. |
developers_can_push |
Boolean |
Explanation: Whether a developer can commit. |
developers_can_merge |
Boolean |
Explanation: Whether a developer can merge. |
master_can_push |
Boolean |
Explanation: Whether an administrator can commit. |
master_can_merge |
Boolean |
Explanation: Whether an administrator can merge. |
no_one_can_push |
Boolean |
Explanation: No one can commit. |
no_one_can_merge |
Boolean |
Explanation: No one can merge. |
in_an_opened_merge_request |
Boolean |
Explanation: Whether it is in an open MR. |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Explanation: SHA ID of a commit. |
short_id |
String |
Explanation: Short SHA ID of a commit. |
created_at |
String |
Explanation: Creation time. |
title |
String |
Explanation: Commit title. |
parent_ids |
Array of strings |
Explanation: Parent commit ID. |
message |
String |
Explanation: Commit message. |
author_name |
String |
Explanation: Author. |
committer_name |
String |
Explanation: Committer. |
committed_date |
String |
Explanation: Commit time. |
Example Requests
{ "ref" : "master", "branch_name" : "test" }
Example Responses
Status code: 200
OK
{ "result" : { "name" : "master", "commit" : { "id" : "3b68902cf0eb7de3d5c8757e4a990bc3fe0af349", "short_id" : "3b68902c", "title" : "Create a File", "created_at" : "2022-03-08T03:14:39.000Z", "parent_ids" : [ "08618c900a4048aae7e4cd88913d3d521eae02eb" ], "message" : "Create a file", "author_name" : "repo", "committer_name" : "repo", "committed_date" : "2022-03-08T03:14:39.000Z" }, "protected" : true, "developers_can_push" : false, "developers_can_merge" : false, "master_can_push" : false, "master_can_merge" : false, "no_one_can_push" : true, "no_one_can_merge" : true, "in_an_opened_merge_request" : false }, "status" : "success" }
Status Codes
Status Code |
Description |
---|---|
200 |
OK |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.