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- The
origingit remote of the current repository - 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”Directoryprojects/
Directorymyworkspace-tools/
Directory.git/
- …
Directorysrc/
Directorycommands/
- …
Directoryservices/
- …
- README.md
When you run bb from myworkspace-tools/, the CLI reads the Bitbucket remote from .git/ and uses that workspace and repository as context.
Examples
Section titled “Examples”Scenario 1: inside a git repository
Section titled “Scenario 1: inside a git repository”# /projects/myrepo has a Bitbucket origin 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, and they work from anywhere — no git repository 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 |
6002 CONTEXT_WORKSPACE_NOT_FOUND |
| Repository-scoped | bb pr *, bb pipeline *, bb issue *, bb commit *, bb status *, bb browse, bb repo view, bb repo delete, bb repo default-reviewers * |
6001 CONTEXT_REPO_NOT_FOUND |
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”git@bitbucket.org:workspace/repo.gitgit@bitbucket.org:workspace/repoHTTPS format
Section titled “HTTPS format”https://bitbucket.org/workspace/repo.githttps://bitbucket.org/workspace/repohttps://username@bitbucket.org/workspace/repo.gitLimitations
Section titled “Limitations”- Only the remote named
originis inspected. If your Bitbucket remote has another name, pass-w/-r. - Repository names containing a dot (
docs.example.com,my.repo) are not parsed. ssh://git@bitbucket.org/workspace/repo.gitis not recognised — use thegit@bitbucket.org:workspace/repoform.
A dotted repository name or an ssh:// URL fails with Remote '<url>' is not a Bitbucket URL. A differently-named remote fails with Git repository has no remote configured.
Error messages
Section titled “Error messages”Repository could not be resolved
Section titled “Repository could not be resolved”Three distinct messages, 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.There is no origin remote — 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.origin points somewhere other than Bitbucket, or the repository name contains a dot — reason: remote_not_bitbucket:
✗ Remote 'git@github.com:acme/tool.git' is not a Bitbucket URL. Use --workspace and --repo options, or run this command from within a Bitbucket repository.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, which every command in the CLI supports — see JSON Output. For the full list of global flags including -w/-r, see Global Flags.