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

# Delete a branch

Deletes the branch and its git ref — the API-side counterpart of pruning a branch in Cube Cloud, for callers that create branches per run (a CI job syncing dbt on every pull request, say) and would otherwise accumulate them forever. Child branches are re-parented onto the deleted branch’s own parent, and anyone viewing the branch in dev mode is moved back to the default branch, so a branch that is currently open is deleted rather than refused. The deploy branch cannot be deleted (400) and an unknown branch is a 404.

`removeOnUpstream=true` additionally deletes the branch on the connected git provider (GitHub/GitLab). It defaults to `false`, so by default the branch is removed from Cube Cloud only and the ref on your own remote is left alone — a CI job cleaning up branches it created itself should opt in explicitly.

`branchName` is a query parameter rather than a path segment because branch names contain slashes (`dbt-sync/main-20260817120000-a1b2c3d4`).


## OpenAPI

````yaml /api-reference/api.yaml delete /build/api/v1/deployments/{deploymentId}/branches
openapi: 3.1.0
info:
  title: Cube Platform API
  version: 1.0.0
  description: >-
    Programmatically manage Cube: deployments and everything scoped to them

    (environments, folders, reports, workbooks, notifications, workspace, and
    agents),

    plus account-level users, groups, policies, embedding, and AI settings.
    Data-model

    authoring, dev mode, branches, and uploads live under /build/api/v1 — same
    host and

    token, routed to the build pods.
servers:
  - url: https://{tenant}.cubecloud.dev
    description: Your tenant host. Replace the whole host if you use a custom domain.
    variables:
      tenant:
        default: your-tenant
        description: Your Cube tenant subdomain
security:
  - bearerAuth: []
tags:
  - name: Deployments
  - name: Deployment Creation
  - name: Environments
  - name: Env Variables
  - name: Regions
  - name: Data Model
  - name: Data Model Uploads
  - name: GitHub
  - name: GitHub Connection
  - name: dbt Sync
  - name: Folders
  - name: Reports
  - name: Workbooks
  - name: Notifications
  - name: Workspace
  - name: Users Admin
  - name: User Attributes
  - name: User Attribute Values
  - name: Tenant Settings
  - name: OAuth Integrations
  - name: User OAuth Tokens
  - name: OIDC Token Configs
  - name: App Theme
  - name: Embed
  - name: Embed Tenants
  - name: Dashboard Embed Access
  - name: OpenAPI Spec
paths:
  /build/api/v1/deployments/{deploymentId}/branches:
    delete:
      tags:
        - Data Model
      summary: Delete a branch
      operationId: removeBranch
      parameters:
        - in: path
          name: deploymentId
          required: true
          schema:
            type: integer
        - in: query
          name: branchName
          required: true
          schema:
            type: string
        - in: query
          name: removeOnUpstream
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataModelWriteResponse'
          description: ''
components:
  schemas:
    DataModelWriteResponse:
      properties:
        success:
          type: boolean
      required:
        - success
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Token authentication. Send `Authorization: Bearer <YOUR_TOKEN>`.'

````