This post is going to illustrate how to sync a fork of a repository to keep it up-to-date with the upstream repository.
Configure an Upstream Remote
Before you can sync your fork with an upstream repository, you must configure a remote that points to the upstream repository in Git.
- List the current configured remote repository for your fork.
- Specify a new remote upstream repository that will be synced with the fork.
- Verify the new upstream repository you've specified for your fork.
Fetch from Upstream Repository
- Direct to the project folder locally
- Fetch the branches and their respective commits from the upstream repository. Commits to
master
will be stored in a local branch,upstream/master
. - Check out your fork's local
master
branch - Merge the changes from
upstream/master
into your localmaster
branch. This brings your fork'smaster
branch into sync with the upstream repository, without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform a "fast-forward": You may also use--no-ff
to merge without Fast-forward.