This guide explains how to migrate a Git repository from Bitbucket to GitHub using the command line. It preserves all branches, tags, and full commit history.
1) Prerequisites
- Git installed locally
- SSH Key setup locally for both BitBucket and Github
- Access to the Bitbucket repository
- A GitHub account with permission to create or push to a repository
2) Clone the Bitbucket repository
In a local directory (outside of your local environment like Local by Flywheel) you will clone the BitBucket repository.
NOTE: this isn’t meant to run a local running environment of the site you will use to develop with, its just meant for migrating from BitBucket to Github, we will delete this from your computer at the end of the process.
Use --mirror to copy all refs, including branches and tags, commit history.
# First command
git clone --mirror git@bitbucket.org:zeitguys/YOUR_REPO.git
# Second command
cd YOUR_REPO.git
NOTE: --mirror is more complete than --bare because it includes all refs and the remote config.
NOTE: This won’t clone like usual where you’ll have working source files, its basically just the .git folder so we can migrate the repo over to bitbucket as explained in the beginning of step 2
3) Create a new empty GitHub repository
- Open https://github.com/new
- Create a new repository with the same or a different name
- Leave it empty
- Do not add a README
- Do not add a
.gitignore - Do not add a license
4) Push the mirror to GitHub
Point origin at your new GitHub repo and push all refs.
Copy the SSH git repo SSH location from GitHub
Ex: git@github.com:Kobayashi-Zeitguys/YOUR_REPO.git
# First Command
git remote set-url origin git@github.com:Kobayashi-Zeitguys/YOUR_REPO.git
# Second Command
git push --mirror
This pushes all branches, all tags, and the full history in a single operation.
5) Verify the migration
Check your remotes and refs locally.
git remote -v
git branch -a
git tag
Then confirm on GitHub that branches, tags, and commit history look correct.
NOTE: Sometimes when migrating the repo to Github, the default branch is incorrectly chosen, use this guide to change the default branch.
6) Optional cleanup
If you no longer need the local mirror clone:
cd ..
rm -rf YOUR_REPO.git
7) What is not migrated by default
This process moves Git data only. It does not migrate:
- Issues
- Pull requests
- Wikis
- Pipelines or CI settings
- Repo permissions and branch protection rules
If you need to migrate issues and pull requests, consider export scripts or GitHub supported migration tools for Bitbucket Cloud to GitHub.
8) Troubleshooting
- If
git push --mirrorfails with a permissions error, make sure you have access to the GitHub repo and that you are using the correct URL or a personal access token. - If the GitHub repo was initialized with files, delete them first or create a brand new empty repo before mirroring.
- If tags or branches appear missing, run
git show-ref --heads --tagslocally to confirm they exist in the mirror, then re-rungit push --mirror. - For very large repositories, consider using SSH to avoid credential prompts or configure Git LFS if you use large file storage.
9) References
- GitHub Docs Create a repo: https://docs.github.com/repositories/creating-and-managing-repositories/creating-a-new-repository
- Git reference for mirroring: https://git-scm.com/docs/git-clone
- GitHub Docs on Wikis: https://docs.github.com/communities/documenting-your-project-with-wikis/about-wikis
10) Done
Your repository is now hosted on GitHub.
