Create a branch
const url = 'https://gitea.com/api/v1/repos/example/example/branches';const options = { method: 'POST', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"new_branch_name":"example","old_branch_name":"example","old_ref_name":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://gitea.com/api/v1/repos/example/example/branches \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --data '{ "new_branch_name": "example", "old_branch_name": "example", "old_ref_name": "example" }'Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Owner of the repo
Name of the repo
Request Body
Section titled “Request Body”CreateBranchRepoOption options when creating a branch in a repository
object
Name of the branch to create
Deprecated: true Name of the old branch to create from
Name of the old branch/tag/commit to create from
Examplegenerated
{ "new_branch_name": "example", "old_branch_name": "example", "old_ref_name": "example"}Responses
Section titled “Responses”Branch
Branch represents a repository branch
object
PayloadCommit represents a commit
object
List of files added in this commit
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
Username of the user
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
Username of the user
Sha1 hash of the commit
The commit message
List of files modified in this commit
List of files removed in this commit
The URL to view this commit
PayloadCommitVerification represents the GPG verification of a commit
object
The signed payload content
The reason for the verification status
The GPG signature of the commit
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
Username of the user
Whether the commit signature is verified
EffectiveBranchProtectionName is the name of the effective branch protection rule
EnableStatusCheck indicates if status checks are enabled
Name is the branch name
Protected indicates if the branch is protected
RequiredApprovals is the number of required approvals for pull requests
StatusCheckContexts contains the list of required status check contexts
UserCanMerge indicates if the current user can merge to this branch
UserCanPush indicates if the current user can push to this branch
Examplegenerated
{ "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": "https://example.com", "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.
The old branch does not exist.
The branch with the same name already exists.
APIRepoArchivedError is an error that is raised when an archived repo should be modified