<!-- auto-generated by cmd/docgen — do not edit -->

# bkt branch

Inspect and manage branches in a Bitbucket repository.

Supports listing, creating, deleting, rebasing, and setting the default branch.
Branch protection rules are available through the "protect" subcommand.

Listing works on both Bitbucket Data Center and Cloud. Create, delete,
set-default, and protect subcommands currently support Data Center only.

```
bkt branch <command> [flags]
```

### Examples

```bash
# List branches in the current context
  bkt branch list

  # Create a branch from main (Data Center)
  bkt branch create feature/login --from main

  # Delete a stale branch (Data Center)
  bkt branch delete feature/old-experiment
```

## Subcommands

| Subcommand | Description | Key Flags |
|---|---|---|
| [create](#bkt-branch-create) | Create a new branch *(DC)* | `--from`, `--message`, `--project`, `--repo` |
| [delete](#bkt-branch-delete) | Delete a branch *(DC)* | `--dry-run`, `--project`, `--repo` |
| [list](#bkt-branch-list) | List branches | `--filter`, `--limit`, `--project`, `--repo` |
| [protect](#bkt-branch-protect) | Manage branch protection rules *(DC)* | — |
| [rebase](#bkt-branch-rebase) | Rebase the current branch onto another branch | `--interactive`, `--no-fetch` |
| [set-default](#bkt-branch-set-default) | Set the default branch *(DC)* | — |

## bkt branch create

Create a new branch in a Bitbucket Data Center repository.

The --from flag is required and specifies the branch or commit to use as the
starting point. An optional --message flag lets you attach a creation message.

This command currently supports Data Center contexts only.

### Usage

```
bkt branch create <branch> [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--from` |  | Branch or commit to start from (required) |
| `--message` |  | Optional branch creation message |
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Create a feature branch from main
  bkt branch create feature/user-auth --from main

  # Create a branch from a specific commit
  bkt branch create hotfix/login --from abc1234

  # Create a branch with a message
  bkt branch create release/v2.0 --from main --message "Release candidate"
```

## bkt branch delete

Delete a branch from a Bitbucket Data Center repository.

Use --dry-run to validate that the branch can be deleted without actually
removing it. This is useful for confirming permissions and branch existence.

This command currently supports Data Center contexts only.

**Alias:** `rm`

### Usage

```
bkt branch delete <branch> [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--dry-run` |  | Perform a dry run without deleting |
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Delete a branch
  bkt branch delete feature/old-experiment

  # Dry-run to verify before deleting
  bkt branch delete feature/old-experiment --dry-run

  # Delete a branch in a specific project and repo
  bkt branch delete bugfix/stale --project MYPROJ --repo backend
```

## bkt branch list

List branches in a Bitbucket repository.

Works on both Bitbucket Data Center and Cloud. On Data Center, uses --project
and --repo to identify the repository. On Cloud, uses --workspace and --repo.
The default branch is marked with an asterisk (*).

**Alias:** `ls`

### Usage

```
bkt branch list [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--filter` |  | Filter branches by text |
| `--limit` |  | Maximum branches to list (0 for all) |
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |
| `--workspace` |  | Bitbucket workspace override (Cloud) |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# List branches in the current context
  bkt branch list

  # Filter branches by name
  bkt branch list --filter feature/

  # List up to 10 branches
  bkt branch list --limit 10

  # List branches in a specific Cloud workspace and repo
  bkt branch list --workspace myteam --repo backend
```

## bkt branch protect

Manage branch protection rules (restrictions) for a Bitbucket Data Center
repository. Supports listing existing restrictions, adding new ones, and
removing them by ID.

Restriction types include no-creates, no-deletes, fast-forward-only, and
require-approvals. Restrictions can target specific users or groups.

This command group currently supports Data Center contexts only.

```
bkt branch protect <command> [flags]
```

### Examples

```bash
# List all branch restrictions
  bkt branch protect list

  # Prevent direct pushes to main
  bkt branch protect add main --type fast-forward-only

  # Remove a restriction by ID
  bkt branch protect remove 42
```

| Subcommand | Description |
|---|---|
| add | Add a branch restriction (DC only) |
| list | List branch restrictions (DC only) |
| remove | Remove a branch restriction (DC only) |

## bkt branch protect add

Add a branch restriction to a Bitbucket Data Center repository.

Available restriction types:
  no-creates          Prevent creating branches matching the pattern
  no-deletes          Prevent deleting branches matching the pattern
  fast-forward-only   Only allow fast-forward merges (no force pushes)
  require-approvals   Require pull request approval before merging

Restrictions can be scoped to specific users or groups with the --user and
--group flags, which are repeatable.

This command currently supports Data Center contexts only.

### Usage

```
bkt branch protect add <branch> [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--group` |  | Group names to apply the restriction to (repeatable) |
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |
| `--type` |  | Restriction type (no-creates, no-deletes, fast-forward-only, require-approvals) |
| `--user` |  | Usernames to apply the restriction to (repeatable) |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Prevent force pushes to main
  bkt branch protect add main --type fast-forward-only

  # Require PR approvals on release branches
  bkt branch protect add release/v2 --type require-approvals

  # Block branch deletion for specific users
  bkt branch protect add main --type no-deletes --user alice --user bob

  # Restrict a branch for a group
  bkt branch protect add develop --type no-creates --group developers
```

## bkt branch protect list

List all branch restrictions configured for a Bitbucket Data Center repository.

Each restriction is shown with its ID, type, and the branch matcher it applies
to. Use the restriction ID with "protect remove" to delete a rule.

This command currently supports Data Center contexts only.

### Usage

```
bkt branch protect list [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# List all restrictions in the current context
  bkt branch protect list

  # List restrictions for a specific project and repo
  bkt branch protect list --project MYPROJ --repo backend
```

## bkt branch protect remove

Remove a branch restriction from a Bitbucket Data Center repository by its
numeric ID. Use "bkt branch protect list" to find restriction IDs.

This command currently supports Data Center contexts only.

### Usage

```
bkt branch protect remove <restriction-id> [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--project` |  | Bitbucket project key override |
| `--repo` |  | Repository slug override |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Remove a restriction by ID
  bkt branch protect remove 42

  # Remove a restriction in a specific project and repo
  bkt branch protect remove 15 --project MYPROJ --repo backend
```

## bkt branch rebase

Rebase the current local branch onto another branch using git rebase.

By default, all remotes are fetched before rebasing to ensure the target branch
is up to date. Use --no-fetch to skip the fetch step if you have already
fetched recently. Use --interactive to open an interactive rebase session.

This command is a local git convenience wrapper and does not call the Bitbucket
API. It works regardless of whether the context is Data Center or Cloud.

### Usage

```
bkt branch rebase <branch> [flags]
```

### Flags

| Flag | Short | Description |
|---|---|---|
| `--interactive` |  | Run rebase in interactive mode |
| `--no-fetch` |  | Skip fetching before rebase |

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Rebase onto main
  bkt branch rebase main

  # Interactive rebase onto develop
  bkt branch rebase develop --interactive

  # Rebase without fetching first
  bkt branch rebase main --no-fetch
```

## bkt branch set-default

Set the default branch for a Bitbucket Data Center repository.

The default branch is the one shown by default when browsing the repository
and is used as the base for new pull requests.

This command currently supports Data Center contexts only.

### Usage

```
bkt branch set-default <branch> [flags]
```

### Inherited Flags

| Flag | Short | Description |
|---|---|---|
| `--context` | `-c` | Active Bitbucket context name |
| `--format` |  | Output format: json or yaml (alias for --json/--yaml) |
| `--jq` |  | Apply a jq expression (implies JSON when no output format flag is set) |
| `--json` |  | Output in JSON format when supported |
| `--template` |  | Render output using Go templates |
| `--yaml` |  | Output in YAML format when supported |

### Examples

```bash
# Set main as the default branch
  bkt branch set-default main

  # Switch the default branch to develop
  bkt branch set-default develop
```

