Git sync fork with upstream: three safe methods
fetch upstream, merge, push origin — the whole sync. Plus the rebase policy, --force-with-lease, and the GitHub button's fast-forward-only limits.
Git sync fork with upstream is three commands in one direction: upstream → your local main → origin. Nothing on the fork flows back upstream — that's what pull requests are for. git fetch upstream && git merge upstream/main && git push origin main. That's the whole sync.
Git sync fork with upstream: the three steps
- Wire the remote, once per clone.
git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git, thengit remote -vto confirm: origin → your fork, upstream → the original. - Fetch, merge, push.
git checkout main·git fetch upstream·git merge upstream/main·git push origin main. - Remember it exists. The whole routine is the one-liner above. Verify with
git rev-list --count main..upstream/main— 12 before the merge, 0 after.
origin = your fork · upstream = the project you forked from. Point both at your fork and a "sync" quietly does nothing — you fetched from a copy just as stale as your own. A fast-forward is the normal outcome: main had nothing new, so it slides forward and creates no merge commit. Find the upstream URL under the original repo's green Code button.
Nothing on the fork flows back upstream. That's what pull requests are for.
Merge or rebase?
Both land the same code; they differ in the history they leave. Pick one policy per repo.
| Method | Command | History result | Best for |
|---|---|---|---|
| Merge | git merge upstream/main | extra merge commit on diverged branches | feature branches with open PRs — never rewrites anything |
| Rebase | git rebase upstream/main | your commits replayed on top, linear history | keeping your fork's main clean; diverged forks you want to reset |
| GitHub UI | Sync fork button / PR merge | same as merge | quick catch-up with no clone open |
# routine sync, merge policy git fetch upstream && git merge upstream/main && git push origin main # routine sync, rebase policy (linear history) git fetch upstream && git rebase upstream/main && git push --force-with-lease origin main # how far behind am I? git fetch upstream && git rev-list --count main..upstream/main # diverged beyond repair — make main identical to upstream (destructive) git fetch upstream && git reset --hard upstream/main && git push --force-with-lease origin main
--force-with-lease over --force — it refuses to overwrite the remote if someone pushed meanwhile. Never rebase a branch with an open pull request unless you know what you are doing: changing commit IDs can detach the PR from its commits. Sync main with merge; keep PR branches out of it."My fork won't sync" — the four usual suspects
the four failure modes, verbatim
- No
upstreamremote.git remote -vshows only origin;git fetch upstreamfails with'upstream' does not appear to be a git repository. Fix: wire the remote. - Fetched but never merged. Fetching updates
upstream/mainlocally but touches no working branch;git loglooks old after a successful fetch. Fix:git merge upstream/main. - Diverged history. You committed to the fork's main and upstream moved too. If upstream should win:
git reset --hard upstream/main— back up your main-only commits with a branch first. A bad reset isn't fatal:git reflogstill knows the old tip. - Push rejected as non-fast-forward after a rebase. Fix:
git push --force-with-lease origin main.
A fifth, rare case: the upstream URL 404s because the repo was renamed or deleted. GitHub redirects renamed repos, so a hard failure usually means deleted or made private. The GitHub button has limits too: it only fast-forwards or merges, won't rebase, refuses outright on diverged branches, and syncs only the default branch.
How often?
Before every new piece of work — branch off a fresh main, and no PR starts from a three-week-old version. Active forks: a daily or per-session sync costs seconds. Read-only or deploy forks: subscribe to the upstream releases feed and sync on release. A fork six months behind needs surgery, not a merge.
- tested on git 2.4x · the GitHub Sync fork button · Linux · macOS
- first published 2026-09-06; record refreshed 2026-10-05
- the four failure modes and the button's fast-forward-only behaviour are git's and GitHub's documented behaviour, typed from real syncs