Skip to main content
The Gitea API provides comprehensive endpoints for managing repository branches, including creating, listing, updating, and deleting branches, as well as managing branch protection rules.

List Branches

List all branches in a repository.

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository

Query Parameters

integer
default:"1"
Page number of results (1-based)
integer
Page size of results

Response

Returns an array of branch objects.
string
Branch name
object
Latest commit information
string
Commit SHA
string
Commit message
string
Commit timestamp (ISO 8601)
boolean
Whether the branch is protected
integer
Number of required approvals for PRs to this branch
boolean
Whether status checks are enabled
array
List of required status check contexts
boolean
Whether the current user can push to this branch
boolean
Whether the current user can merge to this branch
string
Name of the effective branch protection rule

Get Branch

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

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository
string
required
Name of the branch to retrieve

Create Branch

Create a new branch in a repository.

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository

Request Body

string
required
Name of the branch to create
string
Name of the reference (branch/tag/commit SHA) to create the branch from. If not specified, uses the default branch.

Response

Returns the created branch object.
The repository must not be empty, and branch names must follow Git reference naming conventions.

Update Branch

Update a branch reference to point to a new commit.

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository
string
required
Name of the branch to update

Request Body

string
required
New commit SHA to point the branch to
string
Expected current commit SHA (for safety check)
boolean
default:"false"
Force update even if it’s not a fast-forward
Force updating a branch can cause data loss if other users have based work on the old commit. Use with caution.

Rename Branch

Rename an existing branch.

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository
string
required
Current name of the branch

Request Body

string
required
New name for the branch
Renaming protected branches or the default branch requires admin or owner permissions.

Delete Branch

Delete a specific branch from a repository.

Path Parameters

string
required
Owner of the repository
string
required
Name of the repository
string
required
Name of the branch to delete
  • You cannot delete the default branch
  • You cannot delete protected branches without proper permissions
  • Deleting a branch is permanent and cannot be undone

Branch Protection

List Branch Protections

List all branch protection rules for a repository.

Get Branch Protection

Get a specific branch protection rule.

Create Branch Protection

Create a new branch protection rule.

Request Body

string
required
Name of the branch protection rule (can be branch name or pattern like release/*)
integer
default:"0"
Priority of this rule (higher priority rules are matched first)
boolean
default:"false"
Allow push to this branch
boolean
default:"false"
Restrict push to whitelisted users/teams
array
Usernames allowed to push
array
Team names allowed to push
boolean
default:"false"
Restrict merge to whitelisted users/teams
array
Usernames allowed to merge
array
Team names allowed to merge
boolean
default:"false"
Require status checks to pass before merging
array
Required status check contexts that must pass
integer
default:"0"
Number of required approvals before merging
boolean
default:"false"
Only count approvals from whitelisted users/teams
boolean
default:"false"
Block merge if there are rejected reviews
boolean
default:"false"
Dismiss approvals when new commits are pushed
boolean
default:"false"
Require all commits to be signed
boolean
default:"false"
Block merge if branch is not up to date with base

Update Branch Protection

Edit an existing branch protection rule. Only provided fields will be changed.

Delete Branch Protection

Delete a branch protection rule.

Merge Upstream

For forked repositories, merge changes from the upstream repository.

Request Body

string
required
Branch to merge into (typically the default branch)
boolean
default:"false"
Only perform fast-forward merge
This endpoint only works for repositories that are forks. The merge type can be merge, fast-forward, or already-up-to-date.