Understanding Repository Context
Many commands in the Bitbucket CLI need to know which workspace and repository you’re working with. The CLI uses a sophisticated resolution system to determine this automatically, so you don’t always need to specify them explicitly.
Context Resolution Order
The CLI checks multiple sources in this order:
- Command-line flags (
--workspaceand--repo) - Current Git repository (automatically detected from your git remote URL)
- Config file defaults (
workspaceandreposettings) - Combinations of the above sources
Examples
Scenario 1: Inside a Git Repository
# You're in /projects/myrepo, which has a Bitbucket remotecd /projects/myrepobb pr list # ✅ Uses workspace/repo from git remoteThe CLI reads your .git/config and extracts the workspace and repository from the remote URL.
Scenario 2: Using Command-Line Flags
# Explicit specification always takes precedencebb pr list -w myworkspace -r myrepo # ✅ Uses specified valuesThis works from anywhere, even outside a git repository.
Scenario 3: Using Config Defaults
# Set defaults oncebb config set workspace myworkspacebb config set repo myrepo
# Then use commands without flagsbb pr list # ✅ Uses config defaultsScenario 4: Mixed Sources
# Inside a git repo with workspace "gitworkspace/gitrepo"cd /projects/myrepo
# Override just the workspacebb pr list -w anotherworkspace # Uses "anotherworkspace/gitrepo"
# Override just the repobb pr list -r anotherrepo # Uses "gitworkspace/anotherrepo"Repository Argument Formats
Commands that accept a repository argument support multiple formats:
Full Format: workspace/repo
bb repo view myworkspace/myrepobb repo delete myworkspace/myrepo --yesThis explicitly specifies both workspace and repository.
Short Format: repo only
# Uses default workspace from config or git contextbb repo view myrepoThe CLI will:
- Check if you set a default workspace via
bb config set workspace - Check if you’re in a git repository and use its workspace
- Error if neither is available
Supported Remote URL Formats
When detecting context from git, the CLI supports these remote URL formats:
SSH Format
git@bitbucket.org:workspace/repo.gitgit@bitbucket.org:workspace/repoHTTPS Format
https://bitbucket.org/workspace/repo.githttps://bitbucket.org/workspace/repohttps://username@bitbucket.org/workspace/repo.gitError Messages
”Could not determine repository”
This error appears when the CLI can’t figure out which workspace/repo to use.
Solutions:
- Use explicit flags:
-w myworkspace -r myrepo - Run from within a Bitbucket repository
- Set defaults:
bb config set workspace myworkspace
”Repository not found”
The workspace/repo combination was determined but doesn’t exist.
Check:
- Spelling of workspace and repository names
- That you have access to the repository
- That the repository exists in that workspace
Best Practices
For Daily Work
Set your default workspace if you primarily work with one:
bb config set workspace myworkspaceThen work from within your git repositories - context will be automatic.
For Scripts
Always use explicit flags for reliability:
#!/bin/bashWORKSPACE="myworkspace"REPO="myrepo"
bb pr list -w "$WORKSPACE" -r "$REPO" --jsonFor Multi-Workspace Teams
Don’t set a default workspace. Instead, use explicit flags or work from within cloned repositories:
# Each repository is self-containedcd project-a && bb pr list # Uses project-a's workspacecd ../project-b && bb pr list # Uses project-b's workspaceTips
- Use
bb repo viewwith no arguments to see what context the CLI detected - The
--jsonflag works with most commands for scripting - Global flags (
-w,-r,--json) work with all commands