Da Anonimo (non verificato) , 29 Aprile 2026

Cosa otterrai

Manterrai un fork di un repository open-source aggiornato con il suo upstream.

Passo 1: confermare il setup remote

git remote -v
git remote add upstream [email protected]:original-owner/project.git
git remote -v

Passo 2: fetch upstream

git fetch upstream

Passo 3: aggiornare main locale

git checkout main
git merge upstream/main --ff-only

Passo 4: pushare al fork

git push origin main

Passo 5: rebase di branch feature

git checkout feature/login
git rebase main
git push --force-with-lease

Passo 6: configurare comportamento pull

git config pull.rebase true
git config pull.ff only

Opzionale: pulsante "Sync fork" di GitHub

L'UI di GitHub offre un pulsante "Sync fork".

Opzionale: gh repo sync

gh repo sync yourname/project --branch main
# .github/workflows/sync.yml
name: Sync upstream
on:
  schedule:
    - cron: '0 6 * * 1'
  workflow_dispatch:
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: tgymnich/[email protected]
        with:
          owner: original-owner
          base: main
          head: main

Opzionale: pullare tag

git fetch upstream --tags
git push origin --tags

Scenari comuni

Main locale e divergente

git reset --hard upstream/main
git push --force-with-lease origin main

Upstream ha rinominato il branch predefinito

git fetch upstream
git branch -m master main
git branch --set-upstream-to=upstream/main main
git push origin :master main

Dimenticato di sincronizzare per mesi

git fetch upstream
git checkout main
git reset --hard upstream/main
git push --force-with-lease origin main

git checkout feature/whatever
git rebase main

Cadenza best practice

  • Quotidiano per contributori attivi.
  • Settimanale per contributori casuali.
  • Prima di ogni PR al minimo.