Lo que lograrás
Mantendrás un fork de un repositorio open source actualizado con su upstream, sincronizarás tus branches limpiamente, y evitarás la trampa común de dejar tu fork derivar semanas atrás.
Paso 1: confirmar la configuración del remote
git remote -v
git remote add upstream [email protected]:original-owner/project.git
git remote -v
Paso 2: fetch upstream
git fetch upstream
Paso 3: actualizar main local
git checkout main
git merge upstream/main --ff-only
Paso 4: pushear a tu fork
git push origin main
Paso 5: rebasear branches feature
git checkout feature/login
git rebase main
git push --force-with-lease
Paso 6: configurar comportamiento de pull
git config pull.rebase true
git config pull.ff only
Opcional: botón "Sync fork" de GitHub
Opcional: 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
Opcional: traer tags
git fetch upstream --tags
git push origin --tags
Escenarios comunes
Main local ha divergido
git reset --hard upstream/main
git push --force-with-lease origin main
Upstream renombró branch predeterminado
git fetch upstream
git branch -m master main
git branch --set-upstream-to=upstream/main main
git push origin :master main
Cadencia de mejor práctica
- Diariamente para contribuidores activos.
- Semanalmente para contribuidores casuales.
- Antes de cada PR como mínimo.