Refer to:
Configuring a remote for a fork
Syncing a fork
When we fork a repo, we get a forked remote repo, then we clone to local.
If the repo we fork from is updated, we wish to sync with it, we can do this:
Before we can sync with an upstream repo, we must first config a remote which points to to upstream.
- List currently configured remote repos for our fork:
git remote -v
- Specify a new remote upstream repo which will be synced with the forked repo:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- Make sure the new remote upstream is ready:
git remote -v
$ git remote -v
origin http:XXX.git (fetch)
origin http:XXX.git (push)
upstream http:YYY (fetch)
upstream http:YYY (push)
- Fetch the branches and their respective commits from the upstream repo. Commits to
masterwill be stored in a local branchupstream/master.
git fetch upstream
- Checkout to master branch
git checkout master
- Merge the changes from
upstream/masterto our localmaster. This brings our forked repo'smasterbranch in sync with the upstream's repo, without losing our local changes.
git merge upstream/master
# If our branch doesn't have any unique commits, git will instead perform a fast-forward.
- These steps will make our
local projectup to date, but if we want to update our ownremote repo, perhaps agit push origin masteris needed to keep your own remote repo up to date.










网友评论