git GitHub 上的 origin 和 upstream 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9257533/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:58:10  来源:igfitidea点击:

What is the difference between origin and upstream on GitHub?

gitgithubgit-branch

提问by jan

What is the difference between originand upstreamon GitHub?

originupstreamon GitHub 有什么区别?

When a git branch -acommand is done, some branches have a prefix of origin(remotes/origin/..) while others have a prefix of upstream(remotes/upstream/..).

当一个git branch -a命令完成时,一些分支的前缀为origin( remotes/origin/..) 而另一些分支的前缀为upstream( remotes/upstream/..)。

回答by VonC

This should be understood in the context of GitHub forks(where you fork a GitHub repo on GitHub before cloning that fork locally).

这应该在GitHub 分叉的上下文中理解(在本地克隆该分叉之前,您在 GitHub 上分叉一个 GitHub 存储库)。

  • upstream通常是指您分叉的原始存储库
    (有关术语的更多信息,另请参阅downstream”和“ upstream”的定义upstream
  • originis your fork: 你自己在 GitHub 上的 repo,是 GitHub 原始 repo 的克隆

From the GitHub page:

从 GitHub 页面:

When a repo is cloned, it has a default remote called originthat points to your fork on GitHub, not the original repo it was forked from.
To keep track of the original repo, you need to add another remote named upstream

当一个 repo 被克隆时,它有一个默认的远程调用origin,它指向你在 GitHub 上的 fork,而不是它被 fork 的原始 repo。
要跟踪原始存储库,您需要添加另一个名为的远程upstream

git remote add upstream git://github.com/<aUser>/<aRepo.git>

(with aUser/aRepothe reference for the original creator and repository, that you have forked)

aUser/aRepo参考您已经分叉的原始创建者和存储库)

You will use upstreamto fetch from the original repo(in order to keep your local copy in sync with the project you want to contribute to).

您将使用upstream从原来的回购取(为了保持你的本地副本同步与您想参与该项目)。

git fetch upstream

(git fetchalone would fetch from originby default, which is not what is needed here)

(默认情况下git fetch单独会从中获取origin,这不是这里需要的)

You will use originto pull and pushsince you can contribute to your own repository.

您将使用origin推拉因为你可以贡献自己的资源库。

git pull
git push

(again, without parameters, 'origin' is used by default)

(同样,没有参数,默认使用'origin')

You will contribute back to the upstreamrepo by making a pull request.

您将upstream通过发出拉取请求来回馈仓库。

fork and upstream

分叉和上游