Introduction
Migrating repositories from Bitbucket to GitHub can be a daunting task, especially when dealing with multiple branches, commits, and tags. To simplify this process, I have created an automated script that efficiently migrates your Bitbucket repository to GitHub while ensuring all branches, commits, and tags remain intact.
This guide will walk you through the process and help you troubleshoot common migration issues.
Why Migrate to GitHub?
GitHub has become the go-to platform for developers due to its vast ecosystem, better integrations, and superior collaboration tools. Whether you're moving due to Atlassian's strategic changes or just prefer GitHub's ecosystem, this script will help you make a seamless transition.
Prerequisites
Before running the script, ensure that you have the following:
- A Bitbucket repository that you want to migrate.
- A GitHub account and a personal access token with repo permissions.
- Git installed on your system.
- Curl for making API requests (installed by default on most systems).
How to Use the Migration Script
Step 1: Clone the Migration Script
Download or clone the script from the GitHub repository:
git clone https://github.com/babarbilal56/bitbucket-to-github-repo-migration.git
cd bitbucket-to-github-repo-migration
Step 2: Run the Script
Execute the script with the following command:
./migrate_repo.sh <BITBUCKET_REPO_URL> <GITHUB_REPO_URL> <GITHUB_ACCESS_TOKEN> <BITBUCKET_USERNAME> <GITHUB_USERNAME>
Example:
./migrate_repo.sh https://bitbucket.org/user/repo.git https://github.com/user/repo.git ghp_xxxxx bitbucket_user github_user
Script Workflow
Clone the Bitbucket Repository
The script clones the repository, including all branches and commits, using:
git clone --bare <BITBUCKET_REPO_URL>
Check if GitHub Repository Exists
- If the repository exists, it skips the creation process.
- If not, it creates a new repository using the GitHub API.
Set Up GitHub Remote
The script adds GitHub as the new remote:
git remote add github <GITHUB_REPO_URL>
Push to GitHub
It pushes all branches, commits, and tags using:
git push --mirror
Clean Up
After migration, it deletes the local repository clone to save space.
Troubleshooting Common Issues
1. GitHub Push Errors
If you encounter an error like:
fatal: RPC failed; curl 55 Recv failure: Connection reset by peer
Try the following solutions:
Increase Git Buffer Size:
git config --global http.postBuffer 524288000
Use SSH Instead of HTTPS:
git remote set-url origin git@github.com:<GITHUB_USERNAME>/<GITHUB_REPO>.git
git push --mirror
Increase Timeout Settings:
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
2. GitHub Repository Not Created
- Ensure that your GitHub token has the correct permissions (repo scope).
- Check GitHub API responses for errors.
- Manually verify the repository's existence by visiting:
https://github.com/<GITHUB_USERNAME>/<GITHUB_REPO>
3. Push Fails for Large Files
If your repository has large files, consider using Git Large File Storage (LFS):
git lfs install
git lfs track "*.largefile"
git add .gitattributes
Enhancing the Script
You can customize the script further by:
- Changing repository visibility from private to public.
- Handling multiple branches by pushing them separately instead of using
--mirror
.
Conclusion
This script provides an efficient way to migrate your Bitbucket repository to GitHub, maintaining all branches, commits, and tags. If you encounter issues, follow the troubleshooting steps outlined above.
For further assistance or contributions, check out the GitHub repository:
- π Migration Script Repository
- π My GitHub Profile
Happy Coding! π
Top comments (0)