“git remote add upstream”有助于实现什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8948803/
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
What does 'git remote add upstream' help achieve?
提问by ben39
I was reading on: https://wiki.diasporafoundation.org/Git_workflow#Rebase_your_development_branch_on_the_latest_upstream
我正在阅读:https: //wiki.diasporafoundation.org/Git_workflow#Rebase_your_development_branch_on_the_latest_upstream
Here is an extract:
这是一个摘录:
Your Repository Up to Date
In order to get the latest updates from the development trunk do a one-time setup to establish the main GitHub repo as a remote by entering:
$ git remote add upstream git://github.com/diaspora/diaspora.git
Rebase Your Development Branch on the Latest Upstream
To keep your development branch up to date, rebase your changes on top of the current state of the upstream master. See the What's git-rebase? section below to learn more about rebasing.
If you've set up an upstream branch as detailed above, and a development branch called 100-retweet-bugfix, you'd update upstream, update your local master, and rebase your branch from it like so:
$ git fetch upstream $ git checkout master $ git rebase upstream/master $ git checkout 100-retweet-bugfix
[make sure all is committed as necessary in branch]
$ git rebase master
您的存储库是最新的
为了从开发主干获取最新更新,请执行一次性设置,通过输入以下命令将主 GitHub 存储库建立为远程:
$ git remote add upstream git://github.com/diaspora/diaspora.git
在最新的上游重新建立您的开发分支
为了使您的开发分支保持最新,请在上游 master 的当前状态之上重新调整您的更改。请参阅什么是 git-rebase?部分以了解有关变基的更多信息。
如果您已经按照上面的详细说明设置了一个上游分支,以及一个名为 100-retweet-bugfix 的开发分支,您将更新上游,更新您的本地主节点,并像这样从它重新设置您的分支:
$ git fetch upstream $ git checkout master $ git rebase upstream/master $ git checkout 100-retweet-bugfix
[确保在分支中根据需要提交所有内容]
$ git rebase master
Why is adding a 'remote upstream' needed in this case? Coudn't I have just done:
为什么在这种情况下需要添加“远程上游”?我不能刚刚完成:
$ git checkout master
$ git pull origin master
$ git checkout 100-retweet-bugfix
[make sure all is committed as necessary in branch]
[确保在分支中根据需要提交所有内容]
$ git rebase master
回答by manojlds
The wiki is talking from a forked repo point of view. You have access to pull and push from origin, which will be your fork of the main diaspora repo. To pull in changes from this main repo, you add a remote, "upstream" in your local repo, pointing to this original and pull from it.
维基正在从分叉回购的角度进行讨论。您可以从源头访问拉和推,这将是您的主要侨民存储库的分支。要从这个主存储库中拉取更改,您可以在本地存储库中添加一个远程“上游”,指向这个原始库并从中拉取。
So "origin" is a clone of your fork repo, from which you push and pull. "Upstream" is a name for the main repo, from where you pull and keep a clone of your fork updated, but you don't have push access to it.
所以“origin”是你的fork repo的一个克隆,你可以从中推拉。“上游”是主存储库的名称,您可以从中拉取并保持分叉的克隆更新,但您没有对它的推送访问权限。
回答by smparkes
This is useful when you have your own origin
which is not upstream
. In other words, you might have your own origin
repo that you do development and local changes in and then occasionally merge upstream
changes. The difference between your example and the highlighted text is that your example assumes you're working with a clone of the upstream repo directly. The highlighted text assumes you're working on a clone of your own repo that was, presumably, originally a clone of upstream.
当您拥有自己的origin
而不是upstream
. 换句话说,您可能有自己的存储origin
库,您可以在其中进行开发和本地更改,然后偶尔合并upstream
更改。您的示例与突出显示的文本之间的区别在于,您的示例假定您正在直接使用上游存储库的克隆。突出显示的文本假设您正在处理自己的存储库的克隆,该存储库可能最初是上游的克隆。
回答by Onceler
I think it could be used for "retroactively forking"
我认为它可以用于“追溯分叉”
If you have a Git repo, and have now decided that it should have forked another repo. Retroactively you would like it to become a fork, without disrupting the team that uses the repo by needing them to target a new repo.
如果您有一个 Git 存储库,并且现在决定它应该分叉另一个存储库。追溯地,您希望它成为一个分叉,而不需要通过需要他们瞄准新的存储库来干扰使用存储库的团队。
But I could be wrong.
但我可能是错的。
回答by Anmol Deep
Let's take an example: You want to contribute to django, so you fork its repository. In the while you work on your feature, there is much work done on the original repo by other people. So the code you forked is not the most up to date. setting a remote upstream and fetching it time to time makes sure your forked repo is in sync with the original repo.
让我们举个例子:你想为 django 做贡献,所以你 fork 了它的存储库。在您处理您的功能时,其他人在原始存储库上做了很多工作。所以你分叉的代码不是最新的。设置远程上游并不时获取它可确保您的分叉仓库与原始仓库同步。