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.

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

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

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

NOTE: git push --mirror 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

cd ..
rm -rf <repo>.git

4. Clone the new repository from GitHub

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

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

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

git status
git branch -a

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