mrsn0.3.0
auth
live

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.

2026-11-233 min read

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

  1. Wire the remote, once per clone. git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git, then git remote -v to confirm: origin → your fork, upstream → the original.
  2. Fetch, merge, push. git checkout main · git fetch upstream · git merge upstream/main · git push origin main.
  3. 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.

MethodCommandHistory resultBest for
Mergegit merge upstream/mainextra merge commit on diverged branchesfeature branches with open PRs — never rewrites anything
Rebasegit rebase upstream/mainyour commits replayed on top, linear historykeeping your fork's main clean; diverged forks you want to reset
GitHub UISync fork button / PR mergesame as mergequick 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
The law: prefer --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
  1. No upstream remote. git remote -v shows only origin; git fetch upstream fails with 'upstream' does not appear to be a git repository. Fix: wire the remote.
  2. Fetched but never merged. Fetching updates upstream/main locally but touches no working branch; git log looks old after a successful fetch. Fix: git merge upstream/main.
  3. 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 reflog still knows the old tip.
  4. 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.

commits behind, main..upstream/main
12 → 0
before the merge, then after
usual suspects
4
reasons a fork "won't sync"
safe methods
3
merge, rebase, GitHub UI

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
0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt