THE GITHTML FIELD GUIDE
Sync a GitHub fork without discarding your own work
To sync a fork, compare its branch with the upstream branch and update through GitHub’s supported sync flow or a deliberate local integration. If the fork has unique commits, inspect them before choosing a strategy. Synchronizing should not silently discard your contributions, and updating the hosted fork does not automatically update every local clone.
Interpret ahead and behind separately
Behind means upstream contains commits absent from the compared fork branch. Ahead means the fork contains commits absent from upstream. A branch can be both, which indicates divergence rather than a simple download gap. The counts do not tell you whether the unique commits are valuable, obsolete, or already represented by different commits elsewhere.
Keep ongoing contributions on topic branches when possible. A fork baseline with unrelated experiments is harder to synchronize and easier to propose accidentally in a pull request. Before any update, identify the exact branch and upstream repository. A fork can contain several branches with different intended relationships, so syncing one is not a blanket operation over all work.
Choose the hosted or local route deliberately
GitHub provides a Sync fork flow for eligible branches. Read the displayed comparison and any conflict warning before accepting an update. For local work, fetch from the verified upstream remote, inspect divergence, and integrate according to project policy. The example only inspects; it does not overwrite a fork branch.
- If the fork has unique commits, preserve them on a clearly named branch before considering any baseline cleanup, and coordinate if others use that branch.
- If the hosted sync reports conflicts, resolve them through a reviewed integration rather than selecting a discard option without understanding which commits would be lost.
git remote -v
git fetch upstream
git log --left-right --oneline main...upstream/main
git diff --stat main upstream/mainVerify both hosted and local state
After the hosted fork is updated, fetch origin in your local clone and inspect its relationship with your local branch. The website update does not automatically move that local branch or preserve local uncommitted edits during a later integration. Treat those as separate steps with separate checks.
Confirm the resulting baseline contains the intended upstream commit and that contribution branches still reference their work. Run relevant checks if you integrated divergent changes. If your fork is ahead but not behind, there may be nothing new to sync; the ahead count is not itself an error that must be erased. A successful sync produces an understood history relationship, not necessarily a zero on every comparison badge.
- If an upstream project squash-merged your contribution, your fork can still show original commits as unique even when their changes are present upstream. Compare the patches and resulting files before treating every ahead commit as unpublished work or discarding it as redundant based only on its subject.
- After refreshing the fork baseline, inspect any open contribution’s comparison separately. Its topic branch does not automatically inherit every baseline update. Decide whether it needs integration for compatibility or review, and avoid modifying a reviewed topic simply to make the fork homepage’s counters look symmetrical.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.