# Migrate from Bitbucket

Codebahn imports Bitbucket Cloud repositories over Git: commits, branches, and tags, with full history. You can import once, or keep a read-only mirror in sync while you work on Bitbucket. Bitbucket Pipelines does not run on Codebahn, so pipelines need a rewrite (see [CI workflows](#ci-workflows)).

## Prerequisites

- A Codebahn account on a paid plan, Solo or Crew (see [getting started](/docs/getting-started/#2-choose-your-plan-1-min))
- Access to the Bitbucket repositories you want to migrate
- Git installed locally (for pointing your clone at the new remote afterward)

### What gets imported

| Bitbucket | Codebahn |
|---|---|
| Commits, branches, tags | Imported |
| Pull requests and comments | Not imported |
| Issues and wikis | Not imported |
| Pipelines and their variables | Not imported; see [CI workflows](#ci-workflows) |
| Workspace members and permissions | Not imported; [invite your team](/docs/getting-started/#7-invite-your-team-1-min) |

Merge open pull requests before the import, or open them again on Codebahn from the imported branches.

## Create a Bitbucket token

Public repositories need no token: leave the username and password empty. For private ones, create an API token, which covers every repository your Bitbucket account can read:

1. In Bitbucket, open your profile menu > **Account settings** > **Security**

2. Click **Create and manage API tokens** > **Create API token with scopes**. Git access requires a token with scopes

3. Set a name and an expiry date, and click **Next**

4. Select **Bitbucket** as the app, and click **Next**

5. Search for **`read:repository:bitbucket`**, tick its checkbox, and click **Next**

6. Click **Create token** and copy the value. It is shown once

On Codebahn you enter this token as a password. The username depends on the type of token:

| Token | Username | Password |
|---|---|---|
| API token | `x-bitbucket-api-token-auth` | The token |
| Repository access token | `x-token-auth` | The token |

A repository access token limits access to one repository. Create it in the repository's settings, under **Security** > **Access tokens**, with **Read** under **Repositories**.

## Option A: one-time import

1. Log in to Codebahn

2. Click **+** > **Import repository** > **Git**

3. In **Clone URL**, enter the HTTPS URL without a username: `https://bitbucket.org/your-workspace/your-repo.git`. The URL that Bitbucket's **Clone** button gives you may contain your username before the `@`; remove it

4. For a private repository, enter the username and password from the table above

5. Leave **This repository will be a mirror** unchecked

6. Choose the owner (your account or an organization) and confirm the repository name

7. Click **Import repository**

After it completes, the Codebahn repository is independent from Bitbucket. Revoke the token when you have imported everything.

## Option B: mirror first

A mirror is a read-only copy that pulls from Bitbucket on a schedule. Your team keeps pushing to Bitbucket, and you switch one repository at a time.

Follow the steps in Option A, but check **This repository will be a mirror**. Then set how often it syncs:

1. Go to **Settings** > **Repository** on the mirror repo

2. Under **Mirror Settings**, set the interval. The default is eight hours and the minimum is ten minutes. Codebahn checks for due mirrors every ten minutes, so a sync can start up to ten minutes after the interval ends

3. Click **Save**

You cannot push to a mirror, and CI does not run on it. Syncs stop when the token expires, so note its expiry date and enter a new token in **Mirror Settings** before then.

When you are ready to switch, stop pushing to Bitbucket, click **Synchronize Now**, and wait for the sync to finish. Then use **Danger Zone** > **Convert to regular repository**. The conversion is permanent, and later commits on Bitbucket will not arrive.

## Migrate several repos

Repeat the import or mirror steps for each repository. One API token works for all of them.

## Manual fallback

Create an empty repository on Codebahn, then clone and push by hand:

```bash
git clone --bare https://bitbucket.org/your-workspace/your-repo.git
cd your-repo.git
git push --mirror git@codebahn.net:your-org/your-repo.git
```

## After import

Point your local clone at Codebahn:

```bash
git remote set-url origin git@codebahn.net:your-org/your-repo.git
```

Add your SSH key first under **Settings > SSH / GPG Keys** if you haven't.

## CI workflows

:::caution[Bitbucket Pipelines does not run on Codebahn]
Codebahn runs GitHub Actions-compatible workflows. Your `bitbucket-pipelines.yml` files are ignored. Rewrite them as Actions workflows in `.github/workflows/`.
:::

A starting map:

| Bitbucket Pipelines | Actions |
|---|---|
| `bitbucket-pipelines.yml` | `.github/workflows/*.yml` |
| `default` | `on: push` with a `branches` filter. Plain `on: push` also runs on tags, which `default` does not |
| `branches` | `on: push` with `branches` |
| `pull-requests` | `on: pull_request` |
| `step` | A job. Pipelines runs steps in order; Actions runs jobs in parallel unless you add `needs` |
| `parallel` | Jobs without `needs` between them |
| `script` | `steps` with `run` |
| `after-script` | A step with `if: always()` |
| `image` | `container` |
| `caches` | `actions/cache` |
| `artifacts` | `actions/upload-artifact` / `actions/download-artifact`. Later Pipelines steps download artifacts automatically; Actions jobs must download them |
| `services` | `services` at job level |
| Variables and secured variables | Variables and secrets, entered again on Codebahn |
| Pipes | No direct equivalent. Use an action or `run` |

Pipelines clones the repository at the start of every step. Actions does not clone automatically: add `actions/checkout` to every job that needs the code.

GitHub's [Actions Importer](https://docs.github.com/en/actions/tutorials/migrate-to-github-actions/automated-migrations/bitbucket-pipelines-migration) converts Bitbucket Pipelines to GitHub workflows, and its `dry-run` command lets you preview the result. We have not tested its output on Codebahn. Port one pipeline at a time, starting with the simplest, and verify each before moving on. See [set up CI](/docs/set-up-ci/) for a working example and [CI compatibility](/docs/ci-runners/#compatibility) for what is supported.

## Troubleshooting

**"The URL contains credentials"**
The clone URL includes a username, such as `https://you@bitbucket.org/...`. Remove everything between `https://` and `bitbucket.org`, and use the username and password fields.

**The clone URL starts with `https://ssh.bitbucket.org`**
You pasted an SSH URL (Bitbucket uses `ssh.bitbucket.org` for SSH), and Codebahn converted it to HTTPS with the SSH hostname. Change `ssh.bitbucket.org` to `bitbucket.org`. Otherwise the import fails after about two minutes with "Failed to connect to ssh.bitbucket.org port 443".

**"Authentication failed"**
Bitbucket returns the same error for a wrong username, a wrong token, and a repository that does not exist. Check that:

- the username matches the token type
- the token was created **with scopes**, for the **Bitbucket** app, and has not expired
- the workspace and repository in the URL are correct, and your Bitbucket account can read them
- a public repository has empty username and password fields, because wrong credentials fail there too

If you use an app password, replace it with an API token; [Atlassian has disabled app passwords](https://support.atlassian.com/bitbucket-cloud/docs/revoke-an-app-password/).

**Mirror syncs stopped**
The token probably expired or was revoked. Enter a new one in **Settings** > **Repository** > **Mirror Settings**.

## You can leave any time

What you import, you can take back out. [Org Settings > Export](/docs/export/) produces a `tar.gz` with every repo's full Git history plus issues, pull requests, labels, milestones, and releases.
