Skip to content

Software companies

How to export Bitbucket repositories with pull requests and comments

By SourceX Editorial · Updated

Short answer

To export Bitbucket repositories with pull requests and comments, take a mirror clone of each repository for the git history, then pull pull requests, comments and activity through the Bitbucket REST API, because review threads are not stored in git. Request every pull request state, keep commit hashes on each record, and reconcile counts before calling the export complete.

Key takeaways

  • A git mirror clone carries commits, branches and tags, but pull request descriptions, comments and approvals live only in Bitbucket.
  • Bitbucket Cloud and Bitbucket Data Center expose pull requests through different REST APIs, so confirm which product you run before writing a script.
  • Ask for merged, declined and superseded pull requests explicitly; an export of open pull requests alone misses most of the review history.
  • Keep commit hashes, comment parent IDs and inline file anchors so every comment can be tied back to the code it discusses.
  • Reconcile pull request and comment counts against the web interface before treating the export as the record of what exists.

Why is a git clone not enough?#

A git clone of a Bitbucket repository carries commits, branches and tags, but not the review layer around them. Pull request titles, descriptions, reviewer approvals, inline comments, tasks and build statuses are stored by Bitbucket itself, outside the git objects your engineers push.

For an AI developer, that review layer is much of the value. It shows what a reviewer objected to, how the author responded and which version was finally merged. Plan the export as two linked pulls: git for code and history, the API for review records, joined by commit hashes. Comments without diffs are hard to read, and diffs without comments are only code history.

Which Bitbucket product are you exporting from?#

Bitbucket Cloud and Bitbucket Data Center, along with older Server installs, expose pull requests through different REST APIs with different paths, pagination and authentication. A script written for one usually fails on the other, so settle this first.

Check history as well as the current host. Repositories that moved from Server to Cloud, or into Bitbucket from another Git host, may have arrived without their older pull requests and comments, because migrations do not always carry review history. If the old system is still running, export from it before it is switched off.

Which Bitbucket product are you exporting from?
ProductWhere review records liveWhat to confirm first
Bitbucket CloudAtlassian-hosted, read through the Cloud REST API by workspace and repositoryWhich credential types Atlassian currently accepts for API access, rate limits and workspace admin access
Bitbucket Data Center or ServerYour own database, read through the server's REST API by project and repositoryServer version, admin access and whether a retirement or migration is already scheduled
Migrated repositoriesPartly on the old host, partly on the new one, or missingWhether older pull requests and comments came across, and whether the old system can still be read
  1. 01Your work records
  2. 02Personal details removed
  3. 03You approve the release
  4. 04Licensed to AI developers
How it works with SourceX: Your work records → Personal details removed → You approve the release → Licensed to AI developers.Illustrative

Step table: mirror clone plus API pulls#

The export runs in seven steps, and only the second touches git. Run everything from one controlled machine with a resumable script that writes one JSON file per pull request, so a rate-limit pause or dropped connection restarts where it stopped instead of from the beginning.

Use a dedicated read-only credential scoped to repositories and pull requests, following Atlassian's current authentication guidance, which has changed over time. Store the output in company storage with access limited to the people preparing it.

Step table: mirror clone plus API pulls
StepWhat to runWhat it capturesWatch out for
1. InventoryList every repository per workspace or project through the API or admin screensNames, project, last activity, size, forksArchived, personal and forked repositories that nobody remembers
2. Mirror clonegit clone --mirror for each repository; git lfs fetch --all where Git LFS is usedAll branches, tags and full commit historyLFS files are not in a plain clone; branches deleted after merge are gone from git
3. List pull requestsPull request list call for each repository, filtered to every stateTitles, descriptions, authors, reviewers, branches, state, timestampsList calls can default to open pull requests only, so request each state explicitly
4. CommentsComment call for each pull request, following every pageGeneral and inline comments, replies, editsPagination stops early if the next-page link is ignored
5. ActivityActivity call for each pull requestApprovals, changes requested, updates, merges and declinesActivity and comments overlap, so deduplicate on comment ID
6. Diffs and commitsDiff and commit-list calls for each pull requestThe exact change reviewed, including declined workDeclined pull requests whose branches were deleted may exist only here
7. ReconcileCompare counts with the web interface and hashes with the mirrorProof that the export is completeGaps from failed pages or permission errors

Which pull request and comment fields should you keep?#

Keep the fields that reconstruct the review conversation and link it to code, and drop presentation data such as avatar links and rendered HTML. Personal identifiers stay in the working export for now; they are replaced with consistent pseudonyms during preparation, not deleted, so one reviewer's comments still read as one person.

  • Pull request: ID, title, description, state, close reason, created, updated and closed timestamps.
  • Branches and commits: source and destination branch names, source and destination commit hashes, merge commit hash.
  • People: author and reviewer account IDs, each reviewer's approval or changes-requested status.
  • Comments: comment ID, parent ID for threaded replies, author ID, body text, created and updated timestamps, deleted flag.
  • Inline anchors: file path, line numbers and the commit the comment was attached to, so outdated comments still point somewhere.
  • Tasks and statuses: open and resolved tasks, plus build and check results reported by CI.
  • Links out: Jira issue keys found in titles, branch names and commit messages, kept as plain text for later joining.

What gaps catch teams out?#

Deleted source branches are the most common gap. Many teams delete a branch when its pull request merges or is declined, so the commits of declined work disappear from the mirror. The pull request diff pulled through the API may be the only surviving copy, which is why step six matters.

Force pushes cause a second gap. Inline comments attached to commits that were later rewritten become outdated, and their line anchors no longer match the final diff. Keep them with their original commit hash rather than dropping them; the back-and-forth around a rewrite is often the most instructive part of a review.

Images pasted into comments, links to external CI systems and comments on forks sit outside the main calls. Decide early whether each is in scope, and record the decision rather than leaving it to whoever runs the script.

Older Bitbucket Cloud repositories may also have used the built-in issue tracker and wiki, which pull request descriptions often reference by issue number. Atlassian announced that both would be removed on August 20, 2026, with issues exportable as a ZIP package holding a db-2.0.json file and an optional attachments folder, and wikis exportable by cloning their separate repository. Confirm whether that content was exported or moved to Jira before you rely on those references.

Illustrative: exporting a long-running Bitbucket workspace#

Illustrative: a fictional logistics software vendor runs Bitbucket Cloud for its main products and still has a Bitbucket Server instance for a retired desktop product. The CTO wants both histories reviewed before the old server is decommissioned.

The team inventories both systems, takes mirror clones, and pulls pull requests in every state with comments, activity and diffs. Reconciliation shows that the Cloud workspace lost the review history of repositories migrated years earlier, while the old server still holds it. The vendor exports from the server first, then keeps the server read-only until the export is checked. The final package joins both sources by commit hash and lists which repositories carry review history and which carry code history only.

How SourceX approaches a Bitbucket export#

SourceX treats the export as part of the SourceX five-step transaction: Supply, Rights, Preparation, Approval and Delivery. The first conversation needs only metadata, such as repository names, years of history and approximate pull request counts. No clone or export leaves the company during the fit check.

During preparation, exported comments are scanned for secrets and personal details as well as the code, since tools such as TruffleHog scan chats, wikis and logs as well as Git. The export method, counts and commit hashes are recorded as provenance in the SourceX Evidence Packet, and large exports stay in the seller's own storage until delivery is approved.

Frequently asked questions

Do we need admin rights to export pull requests?

Read access to a repository is usually enough to read its pull requests through the API, but building a complete repository inventory normally needs workspace or project admin rights. Many teams create one service account with read-only access to every repository in scope, which also makes the export easier to audit.

What file format should the export use?

A practical layout is one git bundle or bare mirror per repository plus one JSON file per pull request, with comments, activity and diff nested inside. Keep the raw API responses as well as any cleaned version, so preparation can be rerun without calling Bitbucket again.

Should forks and personal repositories be included?

Usually not by default. Forks and personal repositories often hold experiments, copied customer code or work by people outside the company. List them in the inventory, then include a specific one only after the CTO confirms the company owns it and it adds history the main repositories lack.

Can Jira issues be joined to the Bitbucket export later?

Yes, if issue keys are preserved. Keep keys found in pull request titles, branch names and commit messages as plain text, and export Jira separately. The two can then be joined by key during preparation, after excluded Jira issues have been removed.

Does exporting change anything in Bitbucket?

No. Mirror clones and API reads leave repositories, pull requests and permissions unchanged. The only operational effect is API load, so run large pulls outside peak hours and respect rate limits rather than adding parallel workers.

Sources

  • Atlassian announced that the Bitbucket Cloud issue tracker and wiki would be removed on August 20, 2026, with issues exportable as a zip file or migratable to Jira and wikis exportable by cloning their separate repository. Source
  • Bitbucket Cloud issue export packages are ZIP files containing a db-2.0.json file and optionally an attachments directory. Source
  • TruffleHog is an AGPL-3.0 open-source secret scanner that scans sources including Git, chats, wikis, logs, object stores and filesystems. Source

Related resources

See if your company qualifies

A short company assessment. No data uploads are needed.

See if your company qualifies