> ## 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.

# repo.deleteBranch()

> Delete a branch from the repository.

> [!WARNING]
>
> This page documents the earlier Code Storage SDKs: `@pierre/storage`, `pierre-storage`, and
> `code-storage-go`. New code uses the [Pierre SDK](https://code.storage/docs/sdks.md). To move code to the new SDK, use the
> [`pierre-migrate`
> skill](https://github.com/pierrecomputer/skills/tree/main/skills/pierre-migrate).

```typescript TypeScript theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
// Delete a branch from the default namespace.
const result = await repo.deleteBranch({
  name: 'feature/old-onboarding',
});

console.log(result.message);

// Delete an ephemeral branch
const ephemeralResult = await repo.deleteBranch({
  name: 'merge/8e831bf0-3f19-45dc-b9b9-8aad571c9017',
  ephemeral: true,
});
```

```python Python theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
# Delete a branch from the default namespace.
result = await repo.delete_branch(name="feature/old-onboarding")
print(result["message"])

# Delete an ephemeral branch
ephemeral_result = await repo.delete_branch(
    name="merge/8e831bf0-3f19-45dc-b9b9-8aad571c9017",
    ephemeral=True,
)
```

```go Go theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
// Delete a branch from the default namespace.
result, err := repo.DeleteBranch(context.Background(), storage.DeleteBranchOptions{
	Name: "feature/old-onboarding",
})
fmt.Println(result.Message)

// Delete an ephemeral branch
ephemeralTrue := true
ephemeralResult, err := repo.DeleteBranch(context.Background(), storage.DeleteBranchOptions{
	Name:      "merge/8e831bf0-3f19-45dc-b9b9-8aad571c9017",
	Ephemeral: &ephemeralTrue,
})
```

Branch names must not start with `refs/`.

The repository's default branch cannot be deleted. This protection only applies to non-ephemeral
branches — an ephemeral branch that shares the same short name as the default branch can still be
deleted.

## Options

**name** `string` *required*

Branch name to delete (e.g. `feature/old-onboarding`). Must not start with `refs/`.

**ephemeral** `boolean`

Delete from the ephemeral namespace instead of the default namespace (default: `false`). Use this
to clean up branches created with `ephemeral: true`.

**refPolicies** `object[]`

Ordered ref policy rules (`{ pattern, ops? }`) in the JWT for this call. Code Storage uses the first rule that matches the target ref. Python: `ref_policies`. Go: `RefPolicies` with type `storage.RefPolicyList`. See [Ref Policies](https://code.storage/docs/repos/ref-policies.md).

## Response

**name** `string`

The deleted branch name.

**ephemeral** `boolean`

Whether the deleted branch was in the ephemeral namespace.

**message** `string`

Confirmation message from the API.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.