Created
May 13, 2024 10:42
-
-
Save oneamitj/31d972dfed1b50880afa60cf585cb52c to your computer and use it in GitHub Desktop.
Migrate repo in BitBucket Organization to GitHub Organization with all branchs and PR.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Input Variables | |
BB_ORG="mybborg" | |
BB_REPO_LIST="repo1,repo2,repo3" | |
GH_ORG="myghorg" | |
# Convert comma-separated list of repositories into an array | |
IFS=',' read -r -a repo_array <<< "$BB_REPO_LIST" | |
# Loop through each repository in the list | |
for repo in "${repo_array[@]}" | |
do | |
echo "Migrating repository $repo from Bitbucket to GitHub..." | |
# Clone the Bitbucket repository with all branches | |
git clone --mirror git@bitbucket.org:$BB_ORG/$repo.git | |
cd $repo.git | |
# Create the GitHub repository using GitHub CLI | |
gh repo create $GH_ORG/$repo --private --confirm | |
# Change remote URL to the new GitHub repository | |
git remote add github git@github.com:$GH_ORG/$repo.git | |
# Push all branches and tags to GitHub | |
git push github --all | |
git push github --tags | |
# Cleanup and move out of the repository directory | |
cd .. | |
rm -rf $repo.git # Remove the repository directory to clean up space | |
echo "Migration completed for $repo" | |
done | |
echo "All repositories have been migrated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment