git 将原始 GitHub 存储库中的新更新拉入分叉的 GitHub 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3903817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pull new updates from original GitHub repository into forked GitHub repository
提问by why
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.
我在 GitHub 上分叉了某人的存储库,并希望使用在原始存储库中进行的提交和更新来更新我的版本。这些是在我分叉副本后制作的。
How can I pull in the changes that were made in the origin and incorporate them into my repository?
如何提取在源中所做的更改并将它们合并到我的存储库中?
回答by VonC
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”:
克隆完成后,您的存储库将有一个名为“
origin
”的遥控器,指向您在 GitHub 上的分叉。
不要让这个名字混淆你,这并不指向你分叉的原始仓库。为了帮助您跟踪该存储库,我们将添加另一个名为“上游”的远程:
$ 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.
您还有一个ruby gem,可以促进那些 GitHub 操作。
See also "Git fork is git clone?".
另请参阅“ Git fork 是 git clone?”。
回答by n00shie
In addition to VonC's answer, you could tweak it to your liking even further.
除了 VonC 的回答之外,您还可以根据自己的喜好进一步调整它。
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.
因为 git pull 本质上是 git fetch + git merge。
回答by Dmitry Pavlov
This videoshows 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 (e.g., Update from original). - Click on
Create pull request
. - Scroll down and click
Merge pull request
and finallyConfirm
merge. If your fork didn't have any changes, you will be able to merge it automatically.
- 在 GitHub 上打开您的分叉。
- 单击
Pull Requests
。 - 单击
New Pull Request
。默认情况下,GitHub 会将原始文件与您的 fork 进行比较,如果您没有进行任何更改,则不应有任何可比较的内容。 - 单击
switching the base
。现在 GitHub 会将您的 fork 与原始版本进行比较,您应该会看到所有最新的更改。 - 单击
Create a pull request
此比较并为您的拉取请求指定一个可预测的名称(例如,从原始更新)。 - 单击
Create pull request
。 - 向下滚动并单击
Merge pull request
,最后Confirm
合并。如果您的 fork 没有任何更改,您将能够自动合并它。
回答by ARK
Use:
用:
git remote add upstream ORIGINAL_REPOSITORY_URL
This will set your upstream to the repository you forked from. Then do this:
这会将您的上游设置为您分叉的存储库。然后这样做:
git fetch upstream
This will fetch all the branches including master from the original repository.
这将从原始存储库中获取包括 master 在内的所有分支。
Merge this data in your local master branch:
将此数据合并到您本地的 master 分支中:
git merge upstream/master
Push the changes to your forked repository i.e. to origin:
将更改推送到您的分叉存储库,即源:
git push origin master
Voila! You are done with the syncing the original repository.
瞧!您已完成同步原始存储库。
回答by sudo bangbang
If you're using the GitHub desktop application, there is a synchronise button on the top right corner. Click on it then Update from <original repo>
near top left.
如果您使用的是 GitHub 桌面应用程序,则右上角有一个同步按钮。单击它然后Update from <original repo>
靠近左上角。
If there are no changes to be synchronised, this will be inactive.
如果没有要同步的更改,这将处于非活动状态。
Here are some screenshotsto make this easy.
以下是一些屏幕截图,可让您轻松完成此操作。
回答by cakraww
If you want to do it without cli, you can do it fully on Github website.
如果你想在没有 cli 的情况下完成,你可以在 Github 网站上完成。
- Go to your fork repository.
- Click on
New pull request
. - Make sure to set your fork as the base repository, and the original (upstream) repository as head repository. Usually you only want to sync the master branch.
Create new pull request
.- Select the arrow to the right of the merging button, and make sure to choose rebase instead of merge. Then click the button. This way, it will not produce unnecessary merge commit.
- Done.
- 转到您的 fork 存储库。
- 单击
New pull request
。 - 确保将您的 fork 设置为基础存储库,并将原始(上游)存储库设置为头存储库。通常你只想同步主分支。
Create new pull request
.- 选择合并按钮右侧的箭头,并确保选择变基而不是合并。然后单击按钮。这样,它就不会产生不必要的合并提交。
- 完毕。
回答by Chan
If there is nothing to lose you could also just delete your fork just go to settings... go to danger zone section below and click delete repository. It will ask you to input the repository name and your password after. After that you just fork the original again.
如果没有什么可失去的,您也可以删除您的分叉,只需转到设置...转到下面的危险区域部分,然后单击删除存储库。之后它会要求您输入存储库名称和密码。之后,您只需再次分叉原件即可。
回答by Saurabh P Bhandari
To automatically sync your forked repository with the parent repository, you could use the Pull Appon GitHub.
要自动将分叉存储库与父存储库同步,您可以使用GitHub 上的Pull App。
Refer to the Readmefor more details.
有关更多详细信息,请参阅自述文件。
For advanced setup where you want to preserve your changes done to the forked repository, refer to my answer on a similar question here.
对于要保留做叉形库更改高级设置,请参阅我的回答对类似的问题在这里。