Par Anonyme (non vérifié) , 29 avril 2026

Ce que vous accomplirez

Vous garderez un fork d'un dépôt open-source à jour avec son upstream, synchroniserez vos branches proprement, et éviterez le piège courant de laisser votre fork dériver.

Étape 1 : confirmer la configuration des remotes

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

Étape 2 : fetch upstream

git fetch upstream

Étape 3 : mettre à jour main local

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

Étape 4 : push vers votre fork

git push origin main

Étape 5 : rebase des branches feature

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

Étape 6 : configurer le comportement de pull

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

Optionnel : bouton "Sync fork" de GitHub

Optionnel : 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

Optionnel : tirer les tags

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

Scénarios courants

Main local a divergé

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

Upstream a renommé la branche par défaut

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

Cadence de bonne pratique

  • Quotidien pour contributeurs actifs.
  • Hebdomadaire pour contributeurs occasionnels.
  • Avant chaque PR au minimum.