> ## Documentation Index
> Fetch the complete documentation index at: https://code.storage/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Branch

> Create a new branch from an existing branch or ref. This is useful for agent workflows, ephemeral previews, or server-side automation where you do not want to clone the repo first.
#### JWT claims
Required scopes: `git:write`  
Requires per repo scope: Yes

Deprecated: Use `/api/repos/{repo_name}/branches/create` instead.



## OpenAPI

````yaml https://api.pierre.code.storage/api/openapi.json post /api/v1/repos/branches/create
openapi: 3.1.0
info:
  description: >-
    The Code Storage HTTP API exposes repository management, Git reads, and
    write workflows over plain HTTPS.


    ## Authentication


    Send a signed JWT in the `Authorization: Bearer <token>` header on every
    request.


    - Organisation-scoped endpoints such as `GET /api/repos` require
    organisation scopes like `org:read`

    - Repository-scoped endpoints require a JWT whose `repo` claim names the
    target repository

    - Write operations require the relevant scope such as `git:write` or
    `repo:write`


    ## Pagination


    List endpoints use cursor-based pagination.


    - `cursor` is an opaque token returned by the previous response

    - `limit` defaults to `20` and is capped per endpoint

    - `has_more` tells you whether another request is available

    - `next_cursor` becomes the next `cursor` value


    ## Paths


    Preferred routes use the shorter `/api/...` form. Legacy `/api/v1/...`
    aliases remain documented where they are still supported and are marked as
    deprecated when a preferred route exists.


    ## Repository names in paths


    - Names containing `/` (or any other character that is not safe in a URL
    path segment) **must** be URL encoded so the value occupies a single path
    segment. For example, `pierre/example` becomes `pierre%2Fexample` and the
    request URL is `/api/repos/pierre%2Fexample/...`.

    - Plain names that contain only URL-safe characters can be sent as-is:
    `/api/repos/dotfiles/...`.

    - The server URL-decodes the value before resolving the repository, so
    double-encoding is not required.


    ## Errors


    Most endpoints return RFC 9457-compatible problem details under
    `application/problem+json`, with a legacy `error` field mirrored from
    `detail`.


    Streaming commit and note workflows may return operation-specific failure
    bodies so callers can inspect partial results, branch state, or workflow
    status without parsing generic error strings.
  title: code.storage
  version: 1.0.0
servers:
  - description: Code Storage tenant cluster
    url: https://api.{cluster}.code.storage
    variables:
      cluster:
        default: cluster
        description: >-
          Tenant cluster identifier (e.g. pierre-dev, pierre-staging,
          pierre-prod).
security: []
tags:
  - description: Create, inspect, update, delete, and synchronise repositories.
    name: Repositories
  - description: Create, delete, list, and compare branches.
    name: Branches
  - description: >-
      Read commit metadata and diffs, or create commits without a local Git
      client.
    name: Commits
  - description: >-
      Read repository trees, file contents, archives, and server-side search
      results.
    name: Files
  - description: List, create, and delete Git tags.
    name: Tags
  - description: Attach and retrieve Git notes for commits or other Git objects.
    name: Notes
  - description: >-
      Trigger upstream synchronisation for repositories backed by an external
      source.
    name: Sync
  - description: Manage generic HTTPS Git credentials for non-GitHub upstreams.
    name: Credentials
paths:
  /api/v1/repos/branches/create:
    post:
      tags:
        - Branches
      summary: Create Branch
      description: >-
        Create a new branch from an existing branch or ref. This is useful for
        agent workflows, ephemeral previews, or server-side automation where you
        do not want to clone the repo first.

        #### JWT claims

        Required scopes: `git:write`  

        Requires per repo scope: Yes


        Deprecated: Use `/api/repos/{repo_name}/branches/create` instead.
      operationId: create_branch_legacy
      requestBody:
        content:
          application/json:
            example:
              base_branch: main
              base_is_ephemeral: false
              target_branch: feature/new-onboarding
              target_is_ephemeral: false
            schema:
              additionalProperties: false
              description: >-
                Create-branch request body describing the new branch and its
                base ref.
              properties:
                base_branch:
                  description: >-
                    Preferred source branch name. Use base_ref when you need an
                    exact ref.
                  examples:
                    - main
                  type: string
                base_is_ephemeral:
                  description: >-
                    Whether the base branch should be resolved from the
                    ephemeral namespace.
                  examples:
                    - false
                  type: boolean
                base_ref:
                  description: >-
                    Optional source ref or revision. This supersedes base_branch
                    when provided.
                  type: string
                force:
                  description: >-
                    Allow non-fast-forward updates when recreating an existing
                    branch.
                  type: boolean
                preferred_base:
                  description: >-
                    Optional fallback base branch name used by the backend when
                    it needs another starting point.
                  type: string
                target_branch:
                  description: Destination branch name.
                  examples:
                    - feature/new-onboarding
                  type: string
                target_is_ephemeral:
                  description: >-
                    Whether the new branch should be created in the ephemeral
                    namespace.
                  examples:
                    - false
                  type: boolean
              required:
                - target_branch
              type: object
        description: >-
          Create a branch from another branch or ref. The source and destination
          can live in the default namespace or the ephemeral namespace.
        required: true
      responses:
        '200':
          content:
            application/json:
              example:
                commit_sha: abc123def4567890abc123def4567890abc123de
                message: branch created
                target_branch: feature/new-onboarding
                target_is_ephemeral: false
              schema:
                additionalProperties: false
                description: >-
                  Result of creating a branch, including the resulting ref
                  state.
                properties:
                  commit_sha:
                    description: Resolved commit SHA at the new branch tip.
                    examples:
                      - abc123def4567890abc123def4567890abc123de
                    type: string
                  message:
                    description: Human-readable result message.
                    examples:
                      - branch created
                    type: string
                  target_branch:
                    description: Destination branch name.
                    examples:
                      - feature/new-onboarding
                    type: string
                  target_is_ephemeral:
                    description: Whether the created branch is ephemeral.
                    examples:
                      - false
                    type: boolean
                required:
                  - message
                  - target_branch
                  - target_is_ephemeral
                type: object
          description: Branch creation result.
        '400':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Not Found
        '409':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Conflict
        '429':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Internal Server Error
        '503':
          content:
            application/json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
            application/problem+json:
              schema:
                additionalProperties: false
                description: >-
                  RFC 9457-compatible problem details payload describing the
                  error response.
                properties:
                  detail:
                    description: >-
                      A human-readable explanation specific to this occurrence
                      of the problem.
                    type: string
                  error:
                    description: >-
                      Legacy compatibility field mirroring `detail` for older
                      clients.
                    type: string
                  instance:
                    description: >-
                      A URI reference that identifies the specific occurrence of
                      the problem.
                    type: string
                  status:
                    description: >-
                      The HTTP status code generated by the origin server for
                      this occurrence of the problem.
                    format: int64
                    type: integer
                  title:
                    description: A short, human-readable summary of the problem type.
                    type: string
                  type:
                    description: >-
                      A URI reference that identifies the problem type.
                      `about:blank` indicates the generic HTTP status semantics
                      apply.
                    type: string
                required:
                  - type
                  - title
                  - status
                type: object
          description: Service Unavailable
      deprecated: true
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      bearerFormat: JWT
      scheme: bearer
      type: http

````