Was Sie erreichen werden
Sie werden einen Fork eines Open-Source-Repositorys mit seinem upstream auf dem neuesten Stand halten.
Schritt 1: Remote-Setup bestatigen
git remote -v
git remote add upstream [email protected]:original-owner/project.git
git remote -v
Schritt 2: upstream fetchen
git fetch upstream
Schritt 3: lokales main aktualisieren
git checkout main
git merge upstream/main --ff-only
Schritt 4: zum Fork pushen
git push origin main
Schritt 5: Feature-Branches rebasen
git checkout feature/login
git rebase main
git push --force-with-lease
Schritt 6: Pull-Verhalten konfigurieren
git config pull.rebase true
git config pull.ff only
Optional: GitHubs "Sync fork"-Button
GitHubs UI bietet einen "Sync fork"-Button.
Optional: 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
Optional: Tags pullen
git fetch upstream --tags
git push origin --tags
Haufige Szenarien
Lokales main ist divergiert
git reset --hard upstream/main
git push --force-with-lease origin main
Upstream hat den Default-Branch umbenannt
git fetch upstream
git branch -m master main
git branch --set-upstream-to=upstream/main main
git push origin :master main
Vergessen, monatelang zu synchronisieren
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
Best-Practice-Kadenz
- Taglich fur aktive Mitwirkende.
- Wochentlich fur gelegentliche Mitwirkende.
- Vor jeder PR als Minimum.