Thoughts on

A blog of various opinions and ideas on development


Git: Migrating a Team and Their Codebase from Bitbucket to GitHub

Migrating your team and codebase from Bitbucket to GitHub can be a daunting task, especially if you want to preserve all branches and maintain the development history intact. In this post, we’ll go through the process step-by-step and provide you with scripts to make this transition as smooth as possible.


Step 1: Clone the Bitbucket Repository

Firstly, ensure you have a local clone of the Bitbucket repository with all the branches that you need.

git clone --mirror [bitbucket_repo_url] local-repo
cd local-repo

Replace [bitbucket_repo_url] with the URL of your Bitbucket repository.

Step 2: Push All Branches to the New GitHub Repository

The following script will push all branches from your local clone to the new GitHub repository:



# Check if the GitHub repo URL has been provided
if [ -z "$GITHUB_REPO_URL" ]; then
    echo "GitHub repository URL is not set. Please modify the script with your new repository URL."
    exit 1

# Pushing all branches to the new GitHub repository
git push --all "$GITHUB_REPO_URL"

# Pushing all tags to the new GitHub repository
git push --tags "$GITHUB_REPO_URL"

Make sure to replace with the URL of your new GitHub repository.

Save this script as and execute it to migrate all branches and tags:

chmod +x

Step 3: Update the Remotes on Developer Machines

To avoid having everyone re-clone the repository, you can use this script to update the remote URLs on developer machines:


# Your original Bitbucket repository URL

# Your new GitHub repository URL

# Check if the old remote exists and replace it with the new one
if git remote -v | grep -q "$OLD_REPO_URL"; then
    git remote rename origin old-origin
    git remote add origin "$NEW_REPO_URL"
    git remote remove old-origin
    echo "Old remote URL does not match or does not exist."
    echo "Please check the OLD_REPO_URL value and try again."

Make sure to replace the URLs with the actual Bitbucket and GitHub repository URLs. Save this script as and distribute it to your team members. They can run it in their local repository directories:

chmod +x


After following these steps, your team’s new GitHub repository will contain all the branches and tags from the Bitbucket repository. Developer machines will have their remotes updated without the need to re-clone. The scripts provided should streamline the migration process, making the move to GitHub a hassle-free experience.

Remember to verify the integrity and functionality of your new GitHub repository after the migration. Check the branches, pull requests, and ensure the latest code is up and running.

Happy coding in your new home on GitHub!