Diff and Checkout
Review pull request changes with local checkout and diff tooling.
See Global flags for JSON output, workspace/repository selection, and display options.
bb pr checkout
Section titled “bb pr checkout”Check out a pull request’s source branch locally.
bb pr checkout <id> [options]Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
id |
Pull request ID |
Options
Section titled “Options”Only global flags apply.
Examples
Section titled “Examples”# Checkout PR #42 to review locallybb pr checkout 42
# Checkout PR from specific repositorybb pr checkout 42 -w myworkspace -r myrepoThe command fetches only the pull request’s source branch, then checks it out:
- Branch in this repository: it uses the git remote that points at the repository (whatever its name, falling back to
originwhen no remote URL matches) and checks out<source-branch>. A new branch tracks<remote>/<source-branch>. - Branch in a fork: it fetches from the fork’s remote if you have one, otherwise straight from the fork’s URL (same protocol as your remote), and checks it out as
pr-<id>. Your own branches are never touched, even when the fork’s branch has the same name (for examplemain). - Local branch already exists: it is fast-forwarded to the latest commit, and its upstream setting is left alone. Unpushed local commits on top of the pull request are kept. If the branch has diverged from the pull request, the command fails before switching branches rather than overwrite anything.
git errors, such as uncommitted changes that would be overwritten, stop the command and are reported as they are. Fetch progress is shown on stderr.
--json returns { success, pullRequestId, branch, pullRequest }, where branch is the local branch that was checked out.
bb pr diff
Section titled “bb pr diff”View the diff of a pull request in unified diff format.
bb pr diff [id] [options]Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
id |
Pull request ID (optional, defaults to the open PR for the current branch) |
Options
Section titled “Options”| Option | Description |
|---|---|
--color <when> |
Colorize output: auto, always, never (default: auto) |
--name-only |
Show only names of changed files |
--stat |
Show diffstat (files changed, insertions, deletions) |
--web |
Open diff in web browser; prints the URL when stdout is not a terminal |
Examples
Section titled “Examples”# View diff for PR #42bb pr diff 42
# Auto-detect PR from current branchbb pr diff
# Show only changed file namesbb pr diff 42 --name-only
# Show statistics (like git diff --stat)bb pr diff 42 --stat
# Open diff in browserbb pr diff 42 --web
# Return browser URL as JSONbb pr diff 42 --web --json
# Disable colors for piping to file or other commandsbb pr diff 42 --color never > pr-42.patch
# Get diffstat as JSON for scriptingbb pr diff 42 --stat --json--stat output:
src/index.ts | +12 -3src/utils.ts | +4docs/README.md | -8
3 files changed, 16 insertions(+), 11 deletions(-)- When no ID is provided, the command searches for an open pull request whose source branch matches your current git branch
--color autocolors the diff only when stdout is a terminal: green for additions, red for deletions, cyan for hunk headers. Whole lines are colored by their leading marker, there is no language-aware highlighting- On a terminal the diff opens in your pager (
less -FRXunlessBB_PAGERorPAGERsays otherwise). Piped output and--jsonare never paged --color neverforces plain text, which is what you want when redirecting to a file or piping into another command. The global--no-colorflag does the same for every command- The value is validated before the request. A typo fails with
--color must be one of: auto, always, neverplus a(Did you mean never?)suggestion, rather than silently falling back - Passing
--color <when>at all turns the global color setting on, because the CLI resolves color by scanning raw argv for a--colortoken.bb pr diff 42 --color neverstill leaves the diff body uncolored, but it overrides--no-colorandNO_COLORfor everything else that invocation prints. See Global Flags → Precedence summary -wis the global short alias for--workspace. To open the diff in a browser you must spell out--web- For opening other Bitbucket pages (PR detail, files, commits, pipelines, settings) in the browser, see
bb browse