Skip to content

Instantly share code, notes, and snippets.

@Muriano
Last active August 22, 2023 10:52
Show Gist options
  • Save Muriano/fb798a8f8319d49a8feee0abc0740b88 to your computer and use it in GitHub Desktop.
Save Muriano/fb798a8f8319d49a8feee0abc0740b88 to your computer and use it in GitHub Desktop.
Easy migration between bb and gh repos
#!/bin/bash
# Check if GitHub CLI is installed
if ! command -v gh &> /dev/null; then
echo "🚨 Error: GitHub CLI (gh) is not installed. Please install it: https://cli.github.com/"
exit 1
fi
# Check if a repository URL is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <workspace>"
echo "Example: $0 freepik-web"
exit 1
fi
echo "🔄 Switching branch to main / master." && (git checkout main &> /dev/null || git checkout master)
echo "⏳ Updating local repository..."
git pull --all; for remote in `git branch -r | grep -v \>`; do git branch --track ${remote#origin/} $remote; done
git fetch --all
git pull --all
# Get the repository name from the current repository
REPO_NAME=$(basename $(git rev-parse --show-toplevel))
# Set the workspace
WORKSPACE=$1
# Create a new repository in the given workspace
echo "📤 Creating a new GitHub repository..."
gh repo create $WORKSPACE/$REPO_NAME --private
# Change the remote URL to the new GitHub repository
echo "🛠️ Changing remote URL to new GitHub repository..."
git remote rm origin
git remote add origin "git@github.com:$WORKSPACE/$REPO_NAME.git"
# Push the local repository to the new GitHub repository
echo "📦 Pushing local repository to the new GitHub repository..."
git push --all origin
git push --tags origin
echo "✅ Migration complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment