---
title: "Create a branch"
method: POST
path: "/api/v2/projects/{projectId}/branches"
tags: ["Branches"]
---

# Create a branch

`POST /api/v2/projects/{projectId}/branches`

## Request

- Base URL: `https://davinci-app.com`
- URL: `https://davinci-app.com/api/v2/projects/{projectId}/branches`
- Auth: HTTP bearer

Branches from another branch at its latest commit, copying its committed
content. Uncommitted work on the source is not carried over.

Branch names are sanitized, so the created name is not always the requested
one. `branch.name` is what was created and `sanitized` says whether it
differs.

## Query parameters

- `branch` string

## Request body

- CreateBranchRequest
  - `name` string, required
  - `sourceBranch` string: Branch to copy from. Defaults to the `branch` query parameter, or `main`.

## Response `201`

Branch created.

- CreateBranchResponse
  - `branch` object, required
    - `name` string, required: The name actually created, which is the requested one unless it was sanitized.
    - `sourceBranch` string, required
    - `commit` string, nullable: Commit the new branch starts from.
  - `sanitized` boolean, required: True when the created name differs from the requested one.

## Other responses

- `400`: Malformed request parameters or body. Agile requests may return `INVALID_PAGINATION` or `INVALID_IDEMPOTENCY_KEY`.
- `401`: No credential was supplied, or the supplied credential is malformed, expired, or revoked. A credential that is present but unusable is never downgraded to an anonymous request.
- `403`: Authenticated but not authorized. Either the acting user lacks the required resource permission, the key's scope ceiling excludes it, or the endpoint rejects this credential type (`CREDENTIAL_NOT_PERMITTED`).
- `404`: Project not found, or the source branch does not exist. Error code is `SOURCE_BRANCH_NOT_FOUND` for the latter.
- `409`: A branch of that name already exists (`BRANCH_ALREADY_EXISTS`), or the project is no longer running (`PROJECT_NOT_RUNNING`).
- `429`: Request rate exceeded, either globally or for this key.
- `500`: Unexpected server error.
- `502`: The git operation failed inside the engine rather than being refused. Error code is `GIT_OPERATION_FAILED`, or `CHANGES_UNAVAILABLE` and `COMMIT_NOT_RECORDED` for the two cases where a specific step is known to have produced nothing.
- `503`: The project could not be opened in time, or no machine is currently available to run it. Error codes are `PROJECT_NOT_READY`, `SERVER_NOT_AVAILABLE`, and `SERVICE_UNAVAILABLE`. Retry after the interval in `Retry-After`.

## Changes

- **2026-09-15** (v2) `67c8b8616dbb`: 9 info
  - the `success` response property const value `false` was added for the status `400`
  - the `success` response property const value `false` was added for the status `401`
  - the `success` response property const value `false` was added for the status `403`
  - the `success` response property const value `false` was added for the status `404`
  - …5 more
- **2026-09-15** (v2) `48948af37797`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/celedon-solutions/apis/davinci-public-api/changes/api/v2/projects/:projectId/branches/post.md)

---

[API](https://skmtc.dev/celedon-solutions/apis/davinci-public-api.md) - [All operations](https://skmtc.dev/celedon-solutions/apis/davinci-public-api/llms.txt) - [OpenAPI document](https://skmtc.dev/celedon-solutions/apis/davinci-public-api/revisions/279218ca2e8d?raw)
