To sync a fork with the upstream repository, add the original repository as a remote named upstream, fetch it, and merge or rebase its default branch into your fork's branch, then push to your fork. For a quick fix without a terminal, the Sync fork button on your fork's GitHub page does the same thing for you.
Forks do not update themselves. Once the original project gets new commits, your fork falls behind until you bring those commits in. Doing this regularly keeps your pull requests small and avoids merge conflicts.
When you fork, GitHub copies the repository at that moment. After that, the original (upstream) and your fork (origin) evolve separately. The GitHub page for your fork shows messages such as "This branch is 12 commits behind owner:main", which tells you how far it drifted.
Syncing means getting those upstream commits into your fork's branch. It is best to keep your fork's main identical to upstream main and do all of your own work on topic branches.
This is the fastest option when you have no local changes on that branch.
Afterwards, run git pull in your local clone to download the updated branch.
The command line gives you full control and works for any branch.
You only do this one time per clone. If you used gh repo fork --clone, the remote already exists.
git fetch upstream downloads the new commits and updates the remote-tracking branches such as upstream/main, without touching your files. --ff-only makes the merge succeed only when main has no commits of its own, which is the expected state for a clean fork. If it fails, your main has extra commits that upstream lacks.
The GitHub CLI wraps the same idea in one command:
Run without arguments inside a clone, gh repo sync updates the local branch from its remote parent.
If you are working on a feature branch and upstream moved on, update that branch too. Choose rebase or merge.
Rebase replays your commits on top of the newest upstream work and produces a straight history. Because it rewrites commits, the push needs --force-with-lease, which refuses to overwrite the remote branch if someone else changed it. Only rebase branches that you alone use.
Merging keeps your existing commits unchanged and adds a merge commit. It is safer for branches that other people share, and the push is a normal fast-forward.
| Approach | History | Push needs force | Best for |
|---|---|---|---|
Sync fork button or --ff-only | Identical to upstream | No | Keeping main clean |
| Rebase | Linear | Yes, with lease | Your own feature branches |
| Merge | Has merge commits | No | Shared branches |
When both sides edited the same lines, Git stops and marks the files. Open each conflicted file, choose the right lines, remove the conflict markers, then run git add <file>. Finish with git rebase --continue or git commit for a merge. git rebase --abort or git merge --abort returns you to where you started if you want to try again.
This happens when you committed straight to main. If those commits are not needed, reset the branch to upstream:
git reset --hard discards local commits and uncommitted changes, so move anything you want to keep to a new branch first with git branch rescue-work.
Sync before you start new work and before you open or update a pull request. For active projects that can mean daily.
Not when you merge or rebase on a topic branch. The Discard commits option and git reset --hard do delete commits from that branch, so use them only when you mean to.
origin is your fork on GitHub, where you push. upstream is the original repository, where you only fetch from.
Yes. The Sync fork button on GitHub, or gh repo sync owner/fork with the CLI, updates the fork on GitHub without a local clone.
A fork must be updated by hand. Use the Sync fork button for a quick update, or add an upstream remote, fetch it, and fast-forward main. Then rebase or merge upstream/main into your feature branches and push to origin.