Home

Migrazione repository da BitBucket a GitHub

Questa guida descrive il flusso consigliato per migrare i repository BcOK da BitBucket a GitHub preservando: - cronologia commit - branch - tag - remote locale funzionante in VS Code

Prerequisiti

  1. Crea il repository vuoto su GitHub (senza README, senza .gitignore, senza licenza iniziale).
  2. Assicurati di avere accesso in push al repository GitHub.
  3. Se usi HTTPS, prepara un Personal Access Token GitHub.
  4. Verifica di essere nella cartella del repository corretto prima di ogni comando.

Strategia consigliata

Per repository gia' clonati localmente conviene: 1. mantenere il remote BitBucket come storico (old-bitbucket) 2. aggiungere GitHub come origin 3. pushare branch e tag 4. impostare upstream su origin

Procedura standard (repository locale esistente)

Esempio generico:

cd "C:\path\to\repo"

git remote -v

# 1) Conserva il vecchio remote BitBucket
# (se il remote si chiama gia' origin)
git remote rename origin old-bitbucket

# 2) Aggiungi il nuovo remote GitHub
git remote add origin https://github.com/Ottomedia/NOME-REPO.git

# 3) Verifica remote
git remote -v

# 4) Pusha tutti i branch su GitHub
git push origin --all

# 5) Pusha tutti i tag su GitHub
git push origin --tags

# 6) Imposta il branch corrente a tracciare origin
$branch = git branch --show-current
git branch --set-upstream-to=origin/$branch $branch

# 7) Imposta origin come default push
git config remote.pushDefault origin

# 8) Verifica stato tracking
git branch -vv

Caso wiki GitHub

Il wiki GitHub e' un repository separato (.wiki.git).

Esempio:

cd "G:\...\wiki"

git remote rename origin old-bitbucket
git remote add origin https://github.com/Ottomedia/pandora-dev-tools.wiki.git

git push origin --all
git push origin --tags

git branch --set-upstream-to=origin/master master
git config remote.pushDefault origin

Se il push viene rifiutato (storie divergenti)

Capita quando su GitHub esistono gia' commit iniziali (es. README creato via web).

Opzione consigliata (allineare senza perdere cronologia locale):

git fetch origin
git log --oneline --decorate --graph --all -20

Se vuoi che GitHub replichi esattamente il repository locale:

git push origin --all --force-with-lease
git push origin --tags --force-with-lease

Usa --force-with-lease solo se sei sicuro che GitHub debba essere sovrascritto.

Verifiche finali

git remote -v
git branch -vv
git ls-remote --heads origin
git ls-remote --tags origin

Checklist: - origin punta a GitHub - old-bitbucket resta disponibile in sola continuita' storica - branch principali visibili su GitHub - tag visibili su GitHub - push da VS Code va su origin

Comando rapido per migrare in sequenza piu' repository

Adatta il mapping percorso -> URL GitHub:

$repos = @(
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\themes\pandora-wp-client"; Repo = "https://github.com/Ottomedia/pandora-wp-client.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-server-api-gestione-richieste"; Repo = "https://github.com/Ottomedia/pandora-server-api-gestione-richieste.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-crm"; Repo = "https://github.com/Ottomedia/pandora-crm.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-virtuoso"; Repo = "https://github.com/Ottomedia/pandora-virtuoso.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-planning"; Repo = "https://github.com/Ottomedia/pandora-planning.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-fattureincloud"; Repo = "https://github.com/Ottomedia/pandora-fattureincloud.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-amazon-ses-notification"; Repo = "https://github.com/Ottomedia/pandora-amazon-ses-notification.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-neverbounce-quick-test"; Repo = "https://github.com/Ottomedia/pandora-neverbounce-quick-test.git" },
  @{ Path = "C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\pandora-domiciliazione-workflow"; Repo = "https://github.com/Ottomedia/pandora-domiciliazione-workflow.git" }
)

foreach ($r in $repos) {
  Write-Host "\n=== $($r.Path) ===" -ForegroundColor Cyan
  Set-Location $r.Path

  $isGit = git rev-parse --is-inside-work-tree 2>$null
  if ($LASTEXITCODE -ne 0 -or $isGit -ne "true") {
    Write-Warning "Saltato: non e' una repo Git"
    continue
  }

  $hasOrigin = git remote | Select-String -SimpleMatch "origin"
  if ($hasOrigin) {
    git remote rename origin old-bitbucket
  }

  git remote add origin $r.Repo
  git push origin --all
  git push origin --tags

  $branch = git branch --show-current
  if ($branch) {
    git branch --set-upstream-to=origin/$branch $branch
  }

  git config remote.pushDefault origin
  git remote -v
  git branch -vv
}

Note operative post-migrazione

  1. In GitHub configura branch protection (almeno su master/main).
  2. Migra o ricrea la pipeline CI/CD (Bitbucket Pipelines -> GitHub Actions o alternativa).
  3. Aggiorna i riferimenti nei file di documentazione (README, wiki, changelog) da BitBucket a GitHub.
  4. Mantieni old-bitbucket per qualche settimana, poi rimuovilo quando non serve piu'.