Skip to content

Instantly share code, notes, and snippets.

@pajcho
Last active June 3, 2025 12:41
Show Gist options
  • Save pajcho/245cd6826e3fd200c69b07e42b1e3d4c to your computer and use it in GitHub Desktop.
Save pajcho/245cd6826e3fd200c69b07e42b1e3d4c to your computer and use it in GitHub Desktop.
Migrate repo from dev to main
#!/bin/bash
set -e
echo "πŸš€ Starting migration..."
# Check if inside a git repo
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "❌ Not a Git repository. Run this inside your local repo folder."
exit 1
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Step 1: Detach if current branch is main or dev
if [[ "$CURRENT_BRANCH" == "main" || "$CURRENT_BRANCH" == "dev" ]]; then
echo "πŸ“¦ Detaching from current branch ($CURRENT_BRANCH) to allow cleanup..."
git checkout --detach
fi
# Step 2: Delete old main and dev branches if they exist
git branch -D main 2>/dev/null || true
git branch -D dev 2>/dev/null || true
# Step 3: Update remote URL
CURRENT_URL=$(git remote get-url origin)
NEW_PATH="github.com:lotusflare/mtn-web.git"
NEW_PATH_HTTPS="github.com/lotusflare/mtn-web.git"
if [[ "$CURRENT_URL" == git@* ]]; then
UPDATED_URL="git@${NEW_PATH}"
elif [[ "$CURRENT_URL" == https://* ]]; then
UPDATED_URL="https://${NEW_PATH_HTTPS}"
else
echo "❌ Unknown remote URL format: $CURRENT_URL"
exit 1
fi
echo "πŸ”„ Updating remote to: $UPDATED_URL"
git remote set-url origin "$UPDATED_URL"
# Step 4: Fetch new main
echo "πŸ“₯ Fetching from remote..."
git fetch origin
# Step 5: Check out clean main
git checkout -b main origin/main
echo "βœ… Migration complete. You’re now on the new 'main' branch."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment