Sync Fork Branch
Git · Example / how-to
Sync Fork Branch
Git · Example / how-to
📋 Overview
Update your fork’s branch from the upstream repository using remotes, fetch, and rebase or merge.
🔧 Core concepts
| Piece | Role |
|---|---|
upstream remote | Original repo |
origin remote | Your fork |
fetch | Download without merge |
rebase / merge | Integrate upstream |
💡 Examples
One-time remote setup:
git remote add upstream https://github.com/ORG/REPO.git
git remote -vSync main, then update feature branch:
git fetch upstream
git checkout main
git merge --ff-only upstream/main
git push origin main
git checkout feature/my-work
git rebase main
# or: git merge main
git push origin feature/my-workIf rebase rewrote commits already on the fork:
git push --force-with-lease origin feature/my-work⚠️ Pitfalls
- Prefer
--force-with-leaseover--forceto avoid clobbering others’ pushes. - Confusing
originandupstreampushes updates to the wrong place. - Long-lived forks: sync often to reduce conflict size.