Pull new updates from original GitHub repository into forked GitHub repository

I forked someone's repository on GitHub and would like to update my version with commits and updates made in the original repository. These were made after I forked my copy.

How can I pull in the changes that were made in the origin and incorporate them into my repository?


You have to add the original repository (the one you forked) as a remote.

From the GitHub fork man page:

叉子

Once the clone is complete your repo will have a remote named “ origin ” that points to your fork on GitHub.
Don't let the name confuse you, this does not point to the original repo you forked from. To help you keep track of that repo we will add another remote named “upstream”:

$ cd github-services
$ git remote add upstream git://github.com/pjhyett/github-services.git
$ git fetch upstream

# then: (like "git pull" which is fetch + merge)
$ git merge upstream/master master

# or, better, replay your local work on top of the fetched branch
# like a "git pull --rebase"
$ git rebase upstream/master

You have also a ruby gem which can facilitate those GitHub operations.

岔

See also "Git fork is git clone?".


In addition to VonC's answer, you could tweak it to your liking even further.

After fetching from the remote branch, you would still have to merge the commits. I would replace

$ git fetch upstream

with

$ git pull upstream master

since git pull is essentially git fetch + git merge.


This video shows how to update a fork directly from GitHub

Steps:

  • Open your fork on GitHub.
  • Click on Pull Requests .
  • Click on New Pull Request . By default, GitHub will compare the original with your fork, and there shouldn't be anything to compare if you didn't make any changes.
  • Click on switching the base . Now GitHub will compare your fork with the original, and you should see all the latest changes.
  • Click on Create a pull request for this comparison and assign a predictable name to your pull request (eg, Update from original).
  • Click on Create pull request .
  • Scroll down and click Merge pull request and finally Confirm merge. If your fork didn't have any changes, you will be able to merge it automatically.
  • 链接地址: http://www.djcxy.com/p/2980.html

    上一篇: 如何更新分叉回购的请求?

    下一篇: 将原始GitHub存储库中的新更新引入分叉的GitHub存储库