美文网首页Git
Git sync a forked repo

Git sync a forked repo

作者: JaedenKil | 来源:发表于2018-01-30 15:36 被阅读26次

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 master will be stored in a local branch upstream/master.
git fetch upstream
  • Checkout to master branch
git checkout master
  • Merge the changes from upstream/master to our local master. This brings our forked repo's master branch 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 project up to date, but if we want to update our own remote repo, perhaps a git push origin master is needed to keep your own remote repo up to date.

相关文章

网友评论

    本文标题:Git sync a forked repo

    本文链接:https://www.haomeiwen.com/subject/gadczxtx.html