Skip to content

branches

Accessed as client.repos.branches; the async client mirrors it.

ReposBranches

The repos.branches namespace.

create

create(
    owner: str, repo: str, *, new_branch_name: str, old_branch_name: str | None = None, old_ref_name: str | None = None
) -> Branch

Create a branch.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
new_branch_name str

Name of the branch to create

required
old_branch_name str | None

Deprecated: true Name of the old branch to create from

None
old_ref_name str | None

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

None

Returns:

Type Description
Branch

Branch.

Raises:

Type Description
ForbiddenError
  1. The branch is archived or a mirror.
NotFoundError
  1. The old branch does not exist.
ConflictError
  1. The branch with the same name already exists.
PayloadTooLargeError
  1. QuotaExceeded.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateBranch

delete

delete(owner: str, repo: str, branch: str) -> None

Delete a specific branch from a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

branch to delete

required

Returns:

Type Description
None

No content.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoDeleteBranch

get

get(owner: str, repo: str, branch: str) -> Branch

Retrieve a specific branch from a repository, including its effective branch protection.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

branch to get

required

Returns:

Type Description
Branch

Branch.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetBranch

list

list(owner: str, repo: str, *, page: int | None = None, limit: int | None = None) -> Paginated[Branch]

List a repository's branches.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
page int | None

1-based page to start iteration at.

None
limit int | None

Page size; the instance caps it server-side.

None

Returns:

Type Description
Paginated[Branch]

BranchList.

Operation ID: repoListBranches

update

update(owner: str, repo: str, branch: str, *, name: str) -> None

Update a branch.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

name of the branch

required
name str

New branch name

required

Returns:

Type Description
None

No content.

Raises:

Type Description
ForbiddenError
  1. APIForbiddenError is a forbidden error response.
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.

Operation ID: repoUpdateBranch

AsyncReposBranches

The repos.branches namespace.

create

create(
    owner: str, repo: str, *, new_branch_name: str, old_branch_name: str | None = None, old_ref_name: str | None = None
) -> Branch

Create a branch.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
new_branch_name str

Name of the branch to create

required
old_branch_name str | None

Deprecated: true Name of the old branch to create from

None
old_ref_name str | None

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

None

Returns:

Type Description
Branch

Branch.

Raises:

Type Description
ForbiddenError
  1. The branch is archived or a mirror.
NotFoundError
  1. The old branch does not exist.
ConflictError
  1. The branch with the same name already exists.
PayloadTooLargeError
  1. QuotaExceeded.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateBranch

delete

delete(owner: str, repo: str, branch: str) -> None

Delete a specific branch from a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

branch to delete

required

Returns:

Type Description
None

No content.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoDeleteBranch

get

get(owner: str, repo: str, branch: str) -> Branch

Retrieve a specific branch from a repository, including its effective branch protection.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

branch to get

required

Returns:

Type Description
Branch

Branch.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetBranch

list

list(owner: str, repo: str, *, page: int | None = None, limit: int | None = None) -> AsyncPaginated[Branch]

List a repository's branches.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
page int | None

1-based page to start iteration at.

None
limit int | None

Page size; the instance caps it server-side.

None

Returns:

Type Description
AsyncPaginated[Branch]

BranchList.

Operation ID: repoListBranches

update

update(owner: str, repo: str, branch: str, *, name: str) -> None

Update a branch.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
branch str

name of the branch

required
name str

New branch name

required

Returns:

Type Description
None

No content.

Raises:

Type Description
ForbiddenError
  1. APIForbiddenError is a forbidden error response.
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.

Operation ID: repoUpdateBranch