Create a branch
const url = 'https://gitea.example.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.example.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
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
Sha1 hash of the commit
PayloadCommitVerification represents the GPG verification of a commit
object
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
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": "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.
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