---
title: Migrate a Single Repository from Bitbucket to GitHub
url: https://calvin.my/posts/migrate-a-single-repository-from-bitbucket-to-github
published: 2026-08-27
updated: 2026-09-13
category: Operations
tags:
- GitHub
- Bitbucket
- Migrate
- CLI
summary: This guide explains how to migrate a Bitbucket repository to GitHub while preserving its full branch, tag, and commit history. It covers required local tools and access, transferring repository references to an empty or intentionally overwritten destination, cleaning up temporary files, and recloning from GitHub. An optional step renames the default branch from master to main, followed by checks to confirm repository integrity and tracking.
---

# Migrate a Single Repository from Bitbucket to GitHub

## Prerequisites

Before you begin, ensure that:

1\. A new GitHub repository has been created and you have been granted access.  
2\. Git is installed on your local machine.  
3\. The GitHub CLI (`gh`) is installed and authenticated on your local machine.

* * *

## Step-by-Step Guide

1\. Download all branches, tags, and commit history with a bare clone.

```bash
git clone --bare git@bitbucket.org:org/repo.git
cd repo.git
```

2\. Mirror-push the repository to the new GitHub repository

```bash
git push --mirror git@github.com:org/repo.git
```

**NOTE:** `git push --mirror`&nbsp;can overwrite or delete remote references. Confirm that the destination GitHub repository is empty or that overwriting its existing refs is intended before running it.

3\. Delete the local bare Bitbucket repository directory

```bash
cd ..
rm -rf <repo>.git
```

4\. Clone the new repository from GitHub

```bash
git clone git@github.com:org/repo.git
cd <repo>
```

5\. Rename \`master\` to \`main\` and set it as the default branch

```bash
git checkout master
git branch -m master main
git push -u origin main
gh repo edit --default-branch main
git push origin --delete master
git remote set-head origin -a
```

**Note:** Omit this step if you do not need to rename the default branch.

6\. Verify the working tree and branch tracking configuration

```bash
git status
git branch -a
```

After completing these steps, confirm that the GitHub repository contains the expected branches, tags, commit history, and default branch.
