Synchronize a Fork with Upstream Safely
Observe before integrating
In the lab, the maintainer adds a new policy file after the fork is created. Your fork and clone do not automatically contain that new commit. Add the original as a separate remote named upstream if it is not already configured. Fetch upstream to refresh upstream/main. This does not change local main or the fork on the remote. Read the incoming commits with git log main..upstream/main.
Integrate deliberately
Keep main as a synchronization branch when practical and use a separate feature branch for contributions. With a clean working tree on main, git merge --ff-only upstream/main advances main only if no divergent integration is required. If main has diverged, this command refuses; inspect both histories and agree on merge or rebase according to project policy. Do not force-push to erase unexpected work. After successful integration, git push origin main updates your fork if accepted.
Do not confuse synchronization targets
Fetching upstream does not publish to origin. Updating origin/main on the remote does not automatically update an existing feature branch. A feature based on older history may need an explicit integration later; inspect its graph and preserve its work. GitHub also offers hosted fork synchronization and CLI options, but the lab tests Git commands only. When a fork has conflicts or policy restrictions, handle those separately rather than assuming a sync button is always available.
Practice example
git switch maingit status --shortgit fetch upstreamgit log --oneline main..upstream/maingit merge --ff-only upstream/maingit push origin mainRun only in the disposable fixture after the maintainer update. The incoming history has one commit; local main and fork main then equal the upstream tip.
Check your understanding
Predict the three main tips after fetch, after merge and after push. What should you do if --ff-only refuses?
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Synchronize a Fork with Upstream Safely — knowledge check
Reason about fork collaboration and contribution trust boundaries.
After fetching upstream, what normally changes?
What does --ff-only prevent?
Where should a contributor publish synchronized main?
What if the fork main has diverged?
Does synchronizing main update every feature branch?