Skip to content

Create a branch

POST
/repos/{owner}/{repo}/branches
owner
required
string

Owner of the repo

repo
required
string

Name of the repo

Media type application/json

CreateBranchRepoOption options when creating a branch in a repository

object
new_branch_name
required

Name of the branch to create

string
unique items
old_branch_name

Deprecated: true Name of the old branch to create from

string
unique items
old_ref_name

Name of the old branch/tag/commit to create from

string
unique items
Example generated
{
"new_branch_name": "example",
"old_branch_name": "example",
"old_ref_name": "example"
}

Branch

Media type application/json

Branch represents a repository branch

object
commit

PayloadCommit represents a commit

object
added
Array<string>
author

PayloadUser represents the author or committer of a commit

object
email
string format: email
name

Full name of the commit author

string
username
string
committer

PayloadUser represents the author or committer of a commit

object
email
string format: email
name

Full name of the commit author

string
username
string
id

Sha1 hash of the commit

string
message
string
modified
Array<string>
removed
Array<string>
timestamp
string format: date-time
url
string
verification

PayloadCommitVerification represents the GPG verification of a commit

object
payload
string
reason
string
signature
string
signer

PayloadUser represents the author or committer of a commit

object
email
string format: email
name

Full name of the commit author

string
username
string
verified
boolean
effective_branch_protection_name
string
enable_status_check
boolean
name
string
protected
boolean
required_approvals
integer format: int64
status_check_contexts
Array<string>
user_can_merge
boolean
user_can_push
boolean
Example generated
{
"commit": {
"added": [
"example"
],
"author": {
"email": "hello@example.com",
"name": "example",
"username": "example"
},
"committer": {
"email": "hello@example.com",
"name": "example",
"username": "example"
},
"id": "example",
"message": "example",
"modified": [
"example"
],
"removed": [
"example"
],
"timestamp": "2026-04-15T12:00:00Z",
"url": "example",
"verification": {
"payload": "example",
"reason": "example",
"signature": "example",
"signer": {
"email": "hello@example.com",
"name": "example",
"username": "example"
},
"verified": true
}
},
"effective_branch_protection_name": "example",
"enable_status_check": true,
"name": "example",
"protected": true,
"required_approvals": 1,
"status_check_contexts": [
"example"
],
"user_can_merge": true,
"user_can_push": true
}

The branch is archived or a mirror.

Media type application/json

The old branch does not exist.

Media type application/json

The branch with the same name already exists.

Media type application/json

QuotaExceeded

Media type application/json
message
string
user_id
integer format: int64
username
string

APIRepoArchivedError is an error that is raised when an archived repo should be modified

Media type application/json
object
message
string
url
string
Example generated
{
"message": "example",
"url": "example"
}