“ git 远程添加上游”有助于实现什么?

我读到: Https://wiki.diasporafoundation.org/git_workflow#rebase_your_development_branch_on_the_latest_upstream

下面是一段摘录:

您最新的储存库

为了从开发主干获得最新的更新,请执行 通过一次性设置将主 GitHub 回购建立为远程的 输入:

$ git remote add upstream git://github.com/diaspora/diaspora.git

将您的开发分支基于最新的上游

若要使开发分支保持最新,请在顶部重新设置更改的基础 上游主机的当前状态。请参阅 Git-rebase? 下面的部分了解更多关于 rebase 的内容。

如果您已经设置了上游分支(如上所述) ,并且 叫做100-retweet-bugfix 的开发分支,你会更新上游, 更新您的本地主服务器,并像下面这样调整您的分支的基础:

$ git fetch upstream


$ git checkout master


$ git rebase upstream/master


$ git checkout 100-retweet-bugfix

[确保在分支中提交所有必要的内容]

$ git rebase master

为什么在这种情况下需要添加一个“远程上游”:

$ git checkout master


$ git pull origin master


$ git checkout 100-retweet-bugfix

[确保在分支中提交所有必要的内容]

$ git rebase master
146121 次浏览

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.

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.

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.

But I could be wrong.

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.