Fundamentals 8 min read

How to Keep Your Forked GitHub Repository Synchronized with Upstream Changes

This step‑by‑step guide shows how to clone a forked GitHub repository, configure the upstream remote, fetch and merge upstream updates, resolve any conflicts, and push the synchronized code back to your fork, ensuring your local copy stays up to date.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
How to Keep Your Forked GitHub Repository Synchronized with Upstream Changes

Configure the upstream repository

Clone the forked repository to your local machine, for example: git clone [email protected]:secbr/nacos.git Enter the cloned directory:

cd /Users/apple/develop/nacos-request/nacos

Check remote URLs

Run git remote -v to see the current remote URLs. If only the origin (your fork) appears, the upstream has not been set yet.

Add the upstream remote

Set the original repository as upstream (replace the URL with the actual source repository):

git remote add upstream https://github.com/alibaba/nacos.git

Verify with git remote -v; you should now see both origin and upstream entries.

Check local code status

If you have uncommitted changes, run git status and commit them before proceeding:

git add -A
git commit -m "your note"
git push origin master
git status

Fetch updates from upstream

Retrieve the latest commits from the upstream repository: git fetch upstream The fetched commits are stored in remote‑tracking branches such as upstream/develop.

Switch to the target branch

Check out the branch you want to update (e.g., develop):

git checkout develop

Merge upstream changes

Merge the upstream branch into your local branch: git merge upstream/develop If there are conflicts, resolve them manually (or with an IDE), then commit the resolution.

Push the synchronized code to your fork

After a successful merge (and conflict resolution if needed), push the updated branch back to your fork on GitHub:

git add .
git commit -m 'merge from nacos'
git push

The fork now contains the latest upstream changes.

Conclusion

By configuring an upstream remote, fetching, merging, and pushing, you can keep a forked repository aligned with its original source, a essential workflow for contributing to open‑source projects on GitHub.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GitfetchmergeGitHubsyncforkupstream
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.