Understanding Repository Context
Most commands need a workspace and a repository. If you don’t pass -w/-r, the CLI works them out from your git remote, then BB_WORKSPACE, then your config file, in that order.
Context resolution order
Section titled “Context resolution order”-w/--workspaceand-r/--repoon the command line- A Bitbucket git remote of the current repository (see Which remote is used)
- The
BB_WORKSPACEenvironment variable defaultWorkspacein the config file
Sources 3 and 4 only supply a workspace. A repository still has to come from -r or the git remote.
Typical local layout
Section titled “Typical local layout”Run bb from the clone or one of its subdirectories. It reads that repository’s
git remotes to resolve the workspace and repository.
Examples
Section titled “Examples”Scenario 1: inside a git repository
Section titled “Scenario 1: inside a git repository”# /projects/myrepo has a Bitbucket remotecd /projects/myrepobb pr list # workspace and repository come from the remoteThe CLI reads your .git/config and extracts the workspace and repository from the remote URL.
Scenario 2: using command-line flags
Section titled “Scenario 2: using command-line flags”bb pr list -w myworkspace -r myrepoFlags always win. With both flags supplied, no git repository is required.
Scenario 3: using a default workspace
Section titled “Scenario 3: using a default workspace”# Environment variable, useful in CIexport BB_WORKSPACE=myworkspace
# Or persist it in the config filebb config set defaultWorkspace myworkspace
bb repo list # workspace-only command, no repository neededBB_WORKSPACE wins over defaultWorkspace, so a pipeline can override a developer’s persisted default without rewriting the config file.
Scenario 4: mixed sources
Section titled “Scenario 4: mixed sources”# Inside a clone of gitworkspace/gitrepocd /projects/myrepo
# Override just the workspacebb pr list -w anotherworkspace # anotherworkspace/gitrepo
# Override just the repositorybb pr list -r anotherrepo # gitworkspace/anotherrepoWorkspace-only vs repository-scoped commands
Section titled “Workspace-only vs repository-scoped commands”The two classes fail differently when context is missing.
| Class | Commands | Error when unresolved |
|---|---|---|
| Workspace-only | bb repo list, bb repo create, bb repo clone, bb project *, bb snippet *, bb workspace view, bb search code, bb webhook * --scope workspace |
6002 CONTEXT_WORKSPACE_NOT_FOUND |
| Repository-scoped | bb pr *, bb pipeline *, bb commit *, bb status *, bb browse, bb repo view, bb repo delete, bb repo default-reviewers *, bb webhook *, bb branch-restriction *, bb deployment * |
6001 CONTEXT_REPO_NOT_FOUND |
bb ssh-key * and bb gpg-key * act on your own account and ignore -w/-r.
bb api falls in either class depending on the endpoint: it resolves a workspace only if the endpoint contains {workspace}, and a repository only if it contains {repo}.
# Placeholders are filled from the same resolution chainbb api /repositories/{workspace}/{repo}/pullrequestsIf a placeholder can’t be resolved you get Endpoint uses {repo} but no repository could be resolved. Pass --repo or run inside a Bitbucket repo.
Repository argument formats
Section titled “Repository argument formats”Commands that accept a repository argument support two formats.
Full format: workspace/repo
Section titled “Full format: workspace/repo”bb repo view myworkspace/myrepobb repo delete myworkspace/myrepo --yesShort format: repo only
Section titled “Short format: repo only”bb repo view myrepoThe workspace is resolved in the usual order:
-w/--workspace, if you passed it- Otherwise the workspace from the current git remote
- Otherwise
BB_WORKSPACE - Otherwise
defaultWorkspacefrom the config file - Otherwise error
The git remote wins over your config. Running bb repo view myrepo inside a clone of otherws/otherrepo resolves to otherws/myrepo, even if defaultWorkspace is set to something else.
Supported remote URL formats
Section titled “Supported remote URL formats”SSH format
Section titled “SSH format”[email protected]:workspace/repo.git[email protected]:workspace/repossh://[email protected]/workspace/repo.gitssh://[email protected]:443/workspace/repo.gitHTTPS format
Section titled “HTTPS format”https://bitbucket.org/workspace/repo.githttps://bitbucket.org/workspace/repohttps://bitbucket.org/workspace/repo/https://[email protected]/workspace/repo.gitRepository names may contain dots (my.repo, docs.example.com). Only a trailing .git is stripped.
SSH host aliases
Section titled “SSH host aliases”A remote like git@bitbucket-work:workspace/repo.git works when bitbucket-work is a Host entry in your SSH config whose HostName is bitbucket.org. The CLI asks ssh -G for the real hostname, the same lookup git does when it connects.
URL rewrites
Section titled “URL rewrites”url.<base>.insteadOf rules in your git config are applied before the URL is parsed, so a remote such as bb:workspace/repo works if it rewrites to a Bitbucket URL.
Which remote is used
Section titled “Which remote is used”origin, if it points to Bitbucket- Otherwise the Bitbucket remote, if all Bitbucket remotes point to the same repository
- Otherwise
upstream, if it is one of them - Otherwise the CLI stops with an error and asks for
-w/-r
A fork clone with origin (your fork) and upstream (the parent) both on Bitbucket resolves to your fork.
Error messages
Section titled “Error messages”Repository could not be resolved
Section titled “Repository could not be resolved”Four distinct reasons, all error code 6001 CONTEXT_REPO_NOT_FOUND. Under --json each sets a different context.reason.
The working directory is not a git repository, reason: not_a_git_repo:
✗ Not in a git repository. Use --workspace and --repo options, or run this command from within a Bitbucket repository.The repository has no remotes, reason: no_remote:
✗ Git repository has no remote configured. Add a Bitbucket remote with `git remote add origin <url>`, or use --workspace and --repo options, or run this command from within a Bitbucket repository.No remote points to Bitbucket, or origin does but its path isn’t workspace/repo, reason: remote_not_bitbucket. With a single remote the message shows its URL (a password in it is shown as ***), with several it lists their names:
✗ Remote '[email protected]:acme/tool.git' is not a Bitbucket URL. Use --workspace and --repo options, or run this command from within a Bitbucket repository.✗ None of the git remotes (origin, gitlab) is a Bitbucket URL. Use --workspace and --repo options, or run this command from within a Bitbucket repository.Several remotes point to different Bitbucket repositories and neither origin nor upstream is one of them, reason: ambiguous_remote:
✗ Git remotes fork, mirror point to different Bitbucket repositories and neither origin nor upstream is one of them. Use --workspace and --repo options to pick one.Fix any of them with explicit flags: bb pr list -w myworkspace -r myrepo.
No workspace specified
Section titled “No workspace specified”✗ No workspace specified. Use --workspace option or set a default workspace with `bb config set defaultWorkspace <name>`.Error code 6002 CONTEXT_WORKSPACE_NOT_FOUND, thrown by workspace-only commands. Pass -w, export BB_WORKSPACE, or set defaultWorkspace.
“Repository not found”
Section titled ““Repository not found””The workspace and repository resolved, but the pair doesn’t exist or your token can’t see it. Check the spelling, your access, and that the repository lives in that workspace.
See Error Codes for the full list.
Which approach to use
Section titled “Which approach to use”| Situation | Use |
|---|---|
| Interactive work in a clone | Nothing, the git remote resolves it |
| Scripts and automation | Explicit -w/-r on every command |
| CI pipelines | BB_WORKSPACE plus -r, or explicit flags |
| You live in one workspace | bb config set defaultWorkspace <name> |
Don’t set defaultWorkspace if you work across several workspaces. A stale default silently sends commands to the wrong place when you’re outside a clone.
Checking what got resolved
Section titled “Checking what got resolved”bb repo view # the resolved workspace/repositorybb workspace view # the resolved workspaceBoth accept --json. See JSON Output for their response shapes. For the full list of global flags including -w/-r, see Global Flags.