Skip to content

Instantly share code, notes, and snippets.

@pp5x
Created July 13, 2025 23:08
Show Gist options
  • Select an option

  • Save pp5x/9a514a747675eb07e0d049f8544498e1 to your computer and use it in GitHub Desktop.

Select an option

Save pp5x/9a514a747675eb07e0d049f8544498e1 to your computer and use it in GitHub Desktop.
Bitbucket to GitHub Migration Scripts
#!/bin/bash
set -euo pipefail
WORKSPACE="your-workspace"
MIRRORS_DIR="mirrors"
command -v bb >/dev/null 2>&1 || { echo "ERROR: bb command not found" >&2; exit 1; }
command -v git >/dev/null 2>&1 || { echo "ERROR: git command not found" >&2; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "ERROR: jq command not found" >&2; exit 1; }
[[ -d "$MIRRORS_DIR" ]] && rm -rf "$MIRRORS_DIR"
mkdir -p "$MIRRORS_DIR"
repo_count=$(bb repository list --workspace "$WORKSPACE" --output json | jq '. | length')
echo "Found $repo_count repositories"
bb repository list --workspace "$WORKSPACE" --output json | jq -r '.[] | @base64' | while read -r repo_data; do
repo_json=$(echo "$repo_data" | base64 --decode)
slug=$(echo "$repo_json" | jq -r '.slug')
ssh_url=$(echo "$repo_json" | jq -r '.links.clone[] | select(.name == "ssh") | .href')
if [[ -z "$ssh_url" || "$ssh_url" == "null" ]]; then
echo "Skipping $slug (no SSH URL)"
continue
fi
echo "Mirroring: $slug"
git clone --mirror "$ssh_url" "$MIRRORS_DIR/$slug" || echo "Failed to mirror: $slug"
done
ls -1 "$MIRRORS_DIR" 2>/dev/null || echo "No repositories mirrored"
#!/bin/bash
set -euo pipefail
MIRRORS_DIR="mirrors"
PREFIX="bitbucket-"
command -v gh >/dev/null 2>&1 || { echo "ERROR: gh command not found" >&2; exit 1; }
command -v git >/dev/null 2>&1 || { echo "ERROR: git command not found" >&2; exit 1; }
[[ -d "$MIRRORS_DIR" ]] || { echo "ERROR: Mirrors directory not found" >&2; exit 1; }
gh auth status >/dev/null 2>&1 || { echo "ERROR: GitHub CLI not authenticated" >&2; exit 1; }
github_user=$(gh api user --jq .login)
for slug in $(ls -1 "$MIRRORS_DIR"); do
github_name="${PREFIX}${slug}"
mirror_path="$MIRRORS_DIR/$slug"
echo "Processing: $slug -> $github_name"
# Create repository if it doesn't exist
if ! gh repo view "$github_name" >/dev/null 2>&1; then
echo "Creating GitHub repository: $github_name"
gh repo create "$github_name" --private >/dev/null 2>&1 || {
echo "Failed to create: $github_name"
continue
}
fi
# Add GitHub remote and push
github_url="[email protected]:${github_user}/${github_name}.git"
git -C "$mirror_path" remote remove github 2>/dev/null || true
if git -C "$mirror_path" remote add github "$github_url" && \
git -C "$mirror_path" push --mirror github --force >/dev/null 2>&1; then
echo "Successfully uploaded: $github_name"
else
echo "Failed to upload: $github_name"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment