CreateBranch - Create a branch

Updated at:

Creates a branch in a specified repository via OpenAPI.

Applicable editions

Central edition, Region edition

Endpoints and authorization information

  • Obtain an endpoint: Replace {domain} in the API request syntax.

  • Obtain a personal access token.

  • Obtain the organizationId: Required only for the Central edition. Go to the Basic Information page in the Tenant Management console to obtain the organization ID.

Product

Resource

Required permission

Code Management

Branch

Read/Write

Request syntax

Central edition

POST https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/branches

Region edition

POST https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/branches

Request headers

Parameter

Type

Required

Description

Example value

x-yunxiao-token

string

Yes

Personal access token.

pt-0fh3****0fbG_35af****0484

Request parameters

Parameter

Type

Location

Required

Description

Example value

organizationId

string

path

  • Yes: Central edition

  • No: Region edition

The organization ID.

60d54f3daccf2bbd6659f3ad

repositoryId

string

path

Yes

The repository ID or URL-encoded full path.

2813489 or 60de7a6852743a5162b5f957%2FDemoRepo

branch

string

query

Yes

The name of the branch to create.

demo-branch

ref

string

query

Yes

The name of the source branch.

master

Request examples

Central edition

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/branches?branch=demo-branch&ref=master' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484'

Region edition

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/branches?branch=demo-branch&ref=master' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484'

Response parameters

Parameter

Type

Description

Example value

-

object

commit

object

The latest commit on the branch.

authorEmail

string

The author's email address.

username@example.com

authorName

string

The author's name.

Codeup-Demo

authoredDate

string

The time when the author made the commit.

2024-04-05T15:30:45Z

committedDate

string

The time when the committer made the commit.

2024-04-05T15:30:45Z

committerEmail

string

The committer's email address.

username@example.com

committerName

string

The committer's name.

Codeup-Demo

id

string

The commit ID.

45ede4680536406d793e0e629bc771cb9fcaa153

message

string

The commit message.

commit message

parentIds

array[string]

The parent commit IDs.

["3fdaf119cf76539c1a47de0074ac02927ef4c8e1"]

shortId

string

The short ID.

45ede468

stats

object

Line change statistics for the commit.

additions

integer

The number of added lines.

10

deletions

integer

The number of deleted lines.

1

total

integer

The total number of changed lines.

11

title

string

The first line of the commit message.

commit title

defaultBranch

boolean

Whether this is the default branch.

false

name

string

The branch name.

demo-branch

protected

boolean

Whether this is a protected branch.

false

webUrl

string

The web URL of the branch page.

http://codeup.example.com/org-id/repo/demo-branch

Response example

{
    "commit": {
        "authorEmail": "username@example.com",
        "authorName": "Codeup-Demo",
        "authoredDate": "2024-04-05T15:30:45Z",
        "committedDate": "2024-04-05T15:30:45Z",
        "committerEmail": "username@example.com",
        "committerName": "Codeup-Demo",
        "id": "45ede4680536406d793e0e629bc771cb9fcaa153",
        "message": "commit message",
        "parentIds": ["3fdaf119cf76539c1a47de0074ac02927ef4c8e1"],
        "shortId": "45ede468",
        "stats": {
            "additions": 10,
            "deletions": 1,
            "total": 11
        },
        "title": "commit title"
    },
    "defaultBranch": false,
    "name": "demo-branch",
    "protected": false,
    "webUrl": "http://codeup.example.com/org-id/repo/demo-branch"
}

Error codes

API error codes are listed in the Error Code Center.