Sync a GitHub fork with its upstream repository
Fetch from the original repository, update the correct branch, and push to your fork without assuming local commits or branch renames disappear automatically.
Add the original repository as an upstream remote, fetch it, and integrate its branch into the branch you want to update. Push the result to origin, which should point to your fork. Check both URLs before changing anything.
Configure the upstream remote
git remote -v
git remote add upstream https://github.com/original-owner/repository.git
Add it only once. If the name already exists, inspect its URL and correct it deliberately instead of adding another remote. Replace the example URL with the actual original repository.
Update your fork's main branch
With local work saved:
git fetch upstream
git switch main
git merge upstream/main
git push origin main
Use the actual upstream branch name. The merge fast-forwards when possible; if the histories have diverged, it can create a merge commit or report conflicts. For a fork branch intended to remain an untouched mirror, git merge --ff-only upstream/main refuses divergence so you can investigate instead of creating a merge automatically.
If origin/main contains other commits not in your local branch, the push may be rejected. Fetch and reconcile that work rather than forcing over it.
Use GitHub's Sync fork action
On the fork's repository page, choose Sync fork and then Update branch when offered. Having commits of your own does not automatically make web synchronization impossible. If there are merge conflicts, GitHub prompts you to resolve them, potentially through a pull request or local workflow.
After updating through the website, fetch your fork locally so your remote-tracking refs reflect the change. The website does not update a checkout on your computer.
Update a feature branch
git fetch upstream
git switch feature-x
git rebase upstream/main
A rebase can keep a private feature branch linear, but it rewrites its commits. If the branch is already published or used by others, follow the team's policy; a merge may fit better. Publishing a rewritten branch can require a carefully reviewed lease-protected update.
FAQ
Why does Git report unrelated histories?
Verify the remote URL and available history. An ordinary fork relationship should have shared ancestry. A shallow clone or a repository created independently can obscure that relationship; do not automatically add --allow-unrelated-histories to bypass the investigation.
Can synchronization be scheduled?
A scheduled workflow can fetch, integrate, and push with suitable permissions. It still needs conflict handling, failure reporting, and a decision about branches with local work. Treat a community template as code to review, not as a guarantee that every fork stays synchronized safely.
What if upstream renamed its default branch?
Fetch the new branch and inspect git remote show upstream. git remote set-head upstream -a updates the local upstream/HEAD symbolic ref; it does not rename your local branch or rewrite its tracking configuration. Update those separately if needed, and use the correct new branch name in future synchronization commands.
See GitHub's fork synchronization guide, git-remote, and git-merge.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan