Skip to content

bb branch

Create, list and delete branches, and set the default branch and restrictions

12 commands.

bb branch create
Create repository branch
bb branch default
Show or set the repository's default branch (2 commands)
bb branch delete
Delete repository branch
bb branch list
List repository branches
bb branch model
Show the branch a commit belongs to, and set the model's default branch (2 commands)
bb branch restriction
Create, list, update and delete a repository's branch restrictions (5 commands)

bb branch create

Create repository branch

bb branch create <name> [flags]
# Branch off main
bb branch create feature/x --start-point main --repo PROJ/repo
--start-point string
Commit ID or ref to branch from

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  repository       object
    projectKey     string   Project key the repository belongs to.
    slug           string   Repository slug.
  branch           object
    id?            string   Full ref name, for example refs/heads/main.
    displayId?     string   Short branch name, for example main.
    latestCommit?  string   Commit the branch currently points at.
    default        boolean  Whether this is the repository default branch.

bb branch default

Show or set the repository's default branch

get
Get repository default branch
set
Set repository default branch

bb branch default get

Get repository default branch

bb branch default get
# The branch new pull requests target
bb branch default get --repo PROJ/repo

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Runs as usual: this command changes nothing, so there is nothing to hold back

Output with --json, where ? marks a field that can be absent
data
  repository     object
    projectKey   string      Project key the repository belongs to.
    slug         string      Repository slug.
  defaultBranch  object
    id?          string      Full ref name, for example refs/heads/main.
    displayId?   string      Short ref name, for example main.
    type?        BRANCH|TAG

bb branch default set

Set repository default branch

bb branch default set <branch>
# Make develop the default branch
bb branch default set develop --repo PROJ/repo

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  status         string  Outcome of the command.
  repository     object
    projectKey   string  Project key the repository belongs to.
    slug         string  Repository slug.
  defaultBranch  string  Short name of the branch that is now the default.

bb branch delete

Delete repository branch

bb branch delete <branch> [flags]
# Delete a branch; at a terminal bb asks first
bb branch delete feature/x --repo PROJ/repo

# In a script, where nobody can be asked, and only if its tip is still the commit you expect
bb branch delete feature/x --repo PROJ/repo --end-point a1b2c3d --yes
--end-point string
Expected commit at branch tip
-y, --yes
Confirm without being asked; applies only when the target is named with --repo PROJECT/slug

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Asks Bitbucket whether this would go through, without changing anything (server-validated)

Output with --json, where ? marks a field that can be absent
data
  status        string  Outcome of the command.
  repository    object
    projectKey  string  Project key the repository belongs to.
    slug        string  Repository slug.
  branch        string  Short name of the branch that was deleted.

bb branch list

List repository branches

bb branch list [flags]
# A repository's branches
bb branch list --repo PROJ/repo

# Release branches, most recently changed first
bb branch list --repo PROJ/repo --filter release/ --order-by MODIFICATION

# Every branch, however many there are
bb branch list --repo PROJ/repo --all

# With how far each is ahead of and behind the default branch, its last
# commit, its builds and its pull requests
bb branch list --repo PROJ/repo --details

# The same, measured against another branch
bb branch list --repo PROJ/repo --base release/2.4
--all
Return every result rather than the first --limit
--base string
Branch, tag or commit the ahead and behind counts are measured against (defaults to the default branch); implies --details
--details
Show what Bitbucket's branch list shows beside each branch: how far it is ahead of and behind --base, its last commit, its builds and its pull requests
--filter string
Filter text for branch names
--limit int
Maximum number of results to return (default 25)
--order-by string
Branch ordering (one of: ALPHABETICAL, MODIFICATION)
--start int
Start offset for list operations

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Runs as usual: this command changes nothing, so there is nothing to hold back

Output with --json, where ? marks a field that can be absent
data
  repository               object
    projectKey             string                  Project key the repository belongs to.
    slug                   string                  Repository slug.
  branches                 list of object or null  Matching branches.
    id?                    string                  Full ref name, for example refs/heads/main.
    displayId?             string                  Short branch name, for example main.
    latestCommit?          string                  Commit the branch currently points at.
    default                boolean                 Whether this is the repository default branch.
    ahead?                 integer                 With --details: commits the branch has that the base lacks.
    behind?                integer                 With --details: commits the base has that the branch lacks.
    lastCommit?            object                  With --details: the commit the branch points at.
      id?                  string                  Full 40-character SHA1.
      displayId?           string                  Abbreviated SHA1 as Bitbucket renders it.
      message?             string                  Full commit message, including the body.
      author?              object                  Who wrote the change.
        name?              string                  Display name.
        emailAddress?      string                  Email address, when the instance exposes it.
        avatarUrl?         string                  URL of the avatar image, when one is configured.
      authorTimestamp?     integer                 When the change was written, in milliseconds since the epoch.
      committer?           object                  Who committed the change.
        name?              string                  Display name.
        emailAddress?      string                  Email address, when the instance exposes it.
        avatarUrl?         string                  URL of the avatar image, when one is configured.
      committerTimestamp?  integer                 When the change was committed, in milliseconds since the epoch.
      parents?             list of string          Commit ids of the parents.
    builds?                object                  With --details: the builds reported for that commit, by state.
      successful           integer                 Builds reporting SUCCESSFUL.
      failed               integer                 Builds reporting FAILED.
      inProgress           integer                 Builds reporting INPROGRESS.
      unknown              integer                 Builds reporting UNKNOWN.
      cancelled            integer                 Builds reporting CANCELLED.
    pullRequests?          object                  With --details: the pull requests opened from the branch.
      open                 integer                 Pull requests from the branch that are open.
      merged               integer                 Pull requests from the branch that were merged.
      declined             integer                 Pull requests from the branch that were declined.
      only?                object                  The pull request itself, when the branch has exactly one.
        id                 integer                 Pull request number, unique within the repository.
        title              string                  Pull request title.
        state              string                  OPEN, MERGED or DECLINED.

bb branch model

Show the branch a commit belongs to, and set the model's default branch

inspect
Show the branch a commit belongs to
update
Update repository default branch used by branch model settings

bb branch model inspect

Show the branch a commit belongs to

bb branch model inspect <commit> [flags]
# The branch Bitbucket counts a commit as belonging to
bb branch model inspect a1b2c3d --repo PROJ/repo
--all
Return every result rather than the first --limit
--limit int
Maximum number of results to return (default 25)

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Runs as usual: this command changes nothing, so there is nothing to hold back

Output with --json, where ? marks a field that can be absent
data
  repository    object
    projectKey  string                  Project key the repository belongs to.
    slug        string                  Repository slug.
  commit        string                  Commit that was inspected, as it was given on the command line.
  refs          list of object or null  Branches containing the commit.
    id?         string                  Full ref name, for example refs/heads/main.
    displayId?  string                  Short ref name, for example main.
    type?       BRANCH|TAG

bb branch model update

Update repository default branch used by branch model settings

bb branch model update <branch>
# Set the default branch of the branch model
bb branch model update develop --repo PROJ/repo

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  status         string  Outcome of the command.
  repository     object
    projectKey   string  Project key the repository belongs to.
    slug         string  Repository slug.
  defaultBranch  string  Short name of the branch that is now the default.

bb branch restriction

Create, list, update and delete a repository's branch restrictions

create
Create branch restriction
delete
Delete branch restriction
get
Get branch restriction by id
list
List branch restrictions
update
Update branch restriction

bb branch restriction create

Create branch restriction

bb branch restriction create [flags]
# Nobody deletes main
bb branch restriction create --repo PROJ/repo --type no-deletes --matcher-id refs/heads/main

# Only pull requests change release branches, except for one group
bb branch restriction create --repo PROJ/repo --type pull-request-only \
  --matcher-type PATTERN --matcher-id 'release/*' --group release-managers

# The branches the branching model calls hotfixes, or its development branch
bb branch restriction create --repo PROJ/repo --type no-deletes \
  --matcher-type MODEL_CATEGORY --matcher-id HOTFIX
bb branch restriction create --repo PROJ/repo --type fast-forward-only \
  --matcher-type MODEL_BRANCH --matcher-id development
--access-key-id ints
SSH access key id allowed by restriction (repeatable)
--group strings
Group name allowed by restriction (repeatable)
--matcher-id string
Matcher id value
--matcher-type string
Matcher type (one of: BRANCH, MODEL_BRANCH, MODEL_CATEGORY, PATTERN) (default "BRANCH")
--type string
Restriction type (one of: read-only, no-deletes, fast-forward-only, pull-request-only, no-creates)
--user strings
User slug allowed by restriction (repeatable)

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  repository         object
    projectKey       string                                                               Project key the repository belongs to.
    slug             string                                                               Repository slug.
  restriction        object
    id?              integer                                                              Restriction identifier, which get,
                                                                                          update and delete address.
    type?            read-only|no-deletes|fast-forward-only|pull-request-only|no-creates  What the restriction forbids: read-only,
                                                                                          no-deletes, fast-forward-only,
                                                                                          pull-request-only or no-creates.
    matcher?         object                                                               Which refs the restriction applies to.
      id?            string                                                               Matcher value: a branch name, a pattern,
                                                                                          or a model branch id depending on type.
      displayId?     string                                                               Human-readable form of the same thing.
      type?          ANY_REF|BRANCH|PATTERN|MODEL_BRANCH|MODEL_CATEGORY|DEFAULT_BRANCH    ANY_REF, BRANCH, PATTERN, MODEL_BRANCH,
                                                                                          MODEL_CATEGORY or DEFAULT_BRANCH, which
                                                                                          decides how id is read.
    users?           list of object                                                       Users exempt from the restriction.
      id?            integer                                                              User identifier.
      name?          string                                                               Username.
      displayName?   string                                                               Human-readable name.
      emailAddress?  string                                                               Email address, when the instance exposes
                                                                                          it.
      slug?          string                                                               URL-safe form of the username.
      type?          string                                                               Account kind: NORMAL for a person,
                                                                                          SERVICE for an integration account.
      active         boolean                                                              Whether the account is enabled.
    groups?          list of string                                                       Groups exempt from the restriction.
    accessKeys?      list of object                                                       SSH access keys exempt from the
                                                                                          restriction.
      id?            integer                                                              Access key identifier.
      label?         string                                                               Label the key was registered under.
      fingerprint?   string                                                               Fingerprint of the public key.
      permission?    string                                                               Access level the key is granted.
    scope?           PROJECT|REPOSITORY                                                   PROJECT when the restriction is set on
                                                                                          the project, REPOSITORY when on the
                                                                                          repository itself.

bb branch restriction delete

Delete branch restriction

bb branch restriction delete <restriction-id> [flags]

Delete one of the repository's branch restrictions.

A restriction the repository inherits from its project is refused: deleted through the repository, it would be deleted from every repository in the project. bb project branch-restriction delete deletes it there.

# By the id bb branch restriction list prints
bb branch restriction delete 7 --repo PROJ/repo
-y, --yes
Confirm without being asked; applies only when the target is named with --repo PROJECT/slug

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  status         string  Outcome of the command.
  repository     object
    projectKey   string  Project key the repository belongs to.
    slug         string  Repository slug.
  restrictionId  string  Identifier of the restriction that was deleted, as it was given on the command line.

bb branch restriction get

Get branch restriction by id

bb branch restriction get <restriction-id>
# One restriction, by id
bb branch restriction get 7 --repo PROJ/repo

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Runs as usual: this command changes nothing, so there is nothing to hold back

Output with --json, where ? marks a field that can be absent
data
  repository         object
    projectKey       string                                                               Project key the repository belongs to.
    slug             string                                                               Repository slug.
  restriction        object
    id?              integer                                                              Restriction identifier, which get,
                                                                                          update and delete address.
    type?            read-only|no-deletes|fast-forward-only|pull-request-only|no-creates  What the restriction forbids: read-only,
                                                                                          no-deletes, fast-forward-only,
                                                                                          pull-request-only or no-creates.
    matcher?         object                                                               Which refs the restriction applies to.
      id?            string                                                               Matcher value: a branch name, a pattern,
                                                                                          or a model branch id depending on type.
      displayId?     string                                                               Human-readable form of the same thing.
      type?          ANY_REF|BRANCH|PATTERN|MODEL_BRANCH|MODEL_CATEGORY|DEFAULT_BRANCH    ANY_REF, BRANCH, PATTERN, MODEL_BRANCH,
                                                                                          MODEL_CATEGORY or DEFAULT_BRANCH, which
                                                                                          decides how id is read.
    users?           list of object                                                       Users exempt from the restriction.
      id?            integer                                                              User identifier.
      name?          string                                                               Username.
      displayName?   string                                                               Human-readable name.
      emailAddress?  string                                                               Email address, when the instance exposes
                                                                                          it.
      slug?          string                                                               URL-safe form of the username.
      type?          string                                                               Account kind: NORMAL for a person,
                                                                                          SERVICE for an integration account.
      active         boolean                                                              Whether the account is enabled.
    groups?          list of string                                                       Groups exempt from the restriction.
    accessKeys?      list of object                                                       SSH access keys exempt from the
                                                                                          restriction.
      id?            integer                                                              Access key identifier.
      label?         string                                                               Label the key was registered under.
      fingerprint?   string                                                               Fingerprint of the public key.
      permission?    string                                                               Access level the key is granted.
    scope?           PROJECT|REPOSITORY                                                   PROJECT when the restriction is set on
                                                                                          the project, REPOSITORY when on the
                                                                                          repository itself.

bb branch restriction list

List branch restrictions

bb branch restriction list [flags]

List the repository's branch restrictions, and those it inherits from its project, which are marked as inherited. bb project branch-restriction changes an inherited one.

# The repository's restrictions, and those it inherits from its project
bb branch restriction list --repo PROJ/repo

# Only the ones that stop pushes without a pull request
bb branch restriction list --repo PROJ/repo --type pull-request-only
--all
Return every result rather than the first --limit
--limit int
Maximum number of results to return (default 25)
--matcher-id string
Matcher id value
--matcher-type string
Matcher type (one of: BRANCH, MODEL_BRANCH, MODEL_CATEGORY, PATTERN)
--type string
Restriction type (one of: read-only, no-deletes, fast-forward-only, pull-request-only, no-creates)

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Runs as usual: this command changes nothing, so there is nothing to hold back

Output with --json, where ? marks a field that can be absent
data
  repository         object
    projectKey       string                                                               Project key the repository belongs to.
    slug             string                                                               Repository slug.
  restrictions       list of object or null                                               Branch restrictions in scope.
    id?              integer                                                              Restriction identifier, which get,
                                                                                          update and delete address.
    type?            read-only|no-deletes|fast-forward-only|pull-request-only|no-creates  What the restriction forbids: read-only,
                                                                                          no-deletes, fast-forward-only,
                                                                                          pull-request-only or no-creates.
    matcher?         object                                                               Which refs the restriction applies to.
      id?            string                                                               Matcher value: a branch name, a pattern,
                                                                                          or a model branch id depending on type.
      displayId?     string                                                               Human-readable form of the same thing.
      type?          ANY_REF|BRANCH|PATTERN|MODEL_BRANCH|MODEL_CATEGORY|DEFAULT_BRANCH    ANY_REF, BRANCH, PATTERN, MODEL_BRANCH,
                                                                                          MODEL_CATEGORY or DEFAULT_BRANCH, which
                                                                                          decides how id is read.
    users?           list of object                                                       Users exempt from the restriction.
      id?            integer                                                              User identifier.
      name?          string                                                               Username.
      displayName?   string                                                               Human-readable name.
      emailAddress?  string                                                               Email address, when the instance exposes
                                                                                          it.
      slug?          string                                                               URL-safe form of the username.
      type?          string                                                               Account kind: NORMAL for a person,
                                                                                          SERVICE for an integration account.
      active         boolean                                                              Whether the account is enabled.
    groups?          list of string                                                       Groups exempt from the restriction.
    accessKeys?      list of object                                                       SSH access keys exempt from the
                                                                                          restriction.
      id?            integer                                                              Access key identifier.
      label?         string                                                               Label the key was registered under.
      fingerprint?   string                                                               Fingerprint of the public key.
      permission?    string                                                               Access level the key is granted.
    scope?           PROJECT|REPOSITORY                                                   PROJECT when the restriction is set on
                                                                                          the project, REPOSITORY when on the
                                                                                          repository itself.

bb branch restriction update

Update branch restriction

bb branch restriction update <restriction-id> [flags]

Update one of the repository's branch restrictions.

A restriction the repository inherits from its project is refused; bb project branch-restriction update changes it there, for every repository in the project.

# Replace a restriction: what it restricts, where, and who is exempt
bb branch restriction update 7 --repo PROJ/repo --type no-deletes \
  --matcher-type BRANCH --matcher-id refs/heads/main --user alice
--access-key-id ints
SSH access key id allowed by restriction (repeatable)
--group strings
Group name allowed by restriction (repeatable)
--matcher-id string
Matcher id value
--matcher-type string
Matcher type (one of: BRANCH, MODEL_BRANCH, MODEL_CATEGORY, PATTERN)
--type string
Restriction type (one of: read-only, no-deletes, fast-forward-only, pull-request-only, no-creates)
--user strings
User slug allowed by restriction (repeatable)

Inherited from bb branch:

--repo string
Repository as PROJECT/slug (defaults to the repository of the git checkout you are in, then BITBUCKET_PROJECT_KEY + BITBUCKET_REPO_SLUG)

Also takes the global flags.

Dry run: Checks your permission and the current state this depends on, without changing anything (preconditions-checked)

Output with --json, where ? marks a field that can be absent
data
  repository         object
    projectKey       string                                                               Project key the repository belongs to.
    slug             string                                                               Repository slug.
  restriction        object
    id?              integer                                                              Restriction identifier, which get,
                                                                                          update and delete address.
    type?            read-only|no-deletes|fast-forward-only|pull-request-only|no-creates  What the restriction forbids: read-only,
                                                                                          no-deletes, fast-forward-only,
                                                                                          pull-request-only or no-creates.
    matcher?         object                                                               Which refs the restriction applies to.
      id?            string                                                               Matcher value: a branch name, a pattern,
                                                                                          or a model branch id depending on type.
      displayId?     string                                                               Human-readable form of the same thing.
      type?          ANY_REF|BRANCH|PATTERN|MODEL_BRANCH|MODEL_CATEGORY|DEFAULT_BRANCH    ANY_REF, BRANCH, PATTERN, MODEL_BRANCH,
                                                                                          MODEL_CATEGORY or DEFAULT_BRANCH, which
                                                                                          decides how id is read.
    users?           list of object                                                       Users exempt from the restriction.
      id?            integer                                                              User identifier.
      name?          string                                                               Username.
      displayName?   string                                                               Human-readable name.
      emailAddress?  string                                                               Email address, when the instance exposes
                                                                                          it.
      slug?          string                                                               URL-safe form of the username.
      type?          string                                                               Account kind: NORMAL for a person,
                                                                                          SERVICE for an integration account.
      active         boolean                                                              Whether the account is enabled.
    groups?          list of string                                                       Groups exempt from the restriction.
    accessKeys?      list of object                                                       SSH access keys exempt from the
                                                                                          restriction.
      id?            integer                                                              Access key identifier.
      label?         string                                                               Label the key was registered under.
      fingerprint?   string                                                               Fingerprint of the public key.
      permission?    string                                                               Access level the key is granted.
    scope?           PROJECT|REPOSITORY                                                   PROJECT when the restriction is set on
                                                                                          the project, REPOSITORY when on the
                                                                                          repository itself.