GitHub 上的 origin 和 upstream 有什么区别? [英] What is the difference between origin and upstream on GitHub?

查看:55
本文介绍了GitHub 上的 origin 和 upstream 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

origin 和 upstream 有什么区别>GitHub?

What is the difference between origin and upstream on GitHub?

当一个 git branch -a 命令被执行时,它显示的一些分支的前缀为 origin (remotes/origin/..) 而其他的前缀为 upstream (remotes/upstream/..).

When a git branch -a command is executed, some branches it displays have a prefix of origin (remotes/origin/..) while others have a prefix of upstream (remotes/upstream/..).

推荐答案

这应该在 GitHub 分叉(在本地克隆该分叉之前,您在 GitHub 上分叉一个 GitHub 存储库).

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

  • upstream 一般是指你已经分叉的原始 repo
    (另见下游"和上游"的定义" 了解更多关于 upstream 术语)
  • origin 是你的 fork:你自己在 GitHub 上的 repo,是 GitHub 原始 repo 的克隆
  • upstream generally refers to the original repo that you have forked
    (see also "Definition of "downstream" and "upstream"" for more on upstream term)
  • origin is your fork: your own repo on GitHub, clone of the original repo of GitHub

来自 GitHub 页面:

From the GitHub page:

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

When a repo is cloned, it has a default remote called origin that 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

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

(使用 aUser/aRepo 引用您已经分叉的原始创建者和存储库)

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

您将使用上游从原始存储库中获取(以使您的本地副本与您要参与的项目保持同步).

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

git fetch upstream

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

(git fetch alone would fetch from origin by default, which is not what is needed here)

您将使用 origin拉取和推送,因为您可以为自己的存储库做出贡献.

You will use origin to pull and push since you can contribute to your own repository.

git pull
git push

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

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

您将通过制作 upstream 存储库"noreferrer">拉取请求.

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

这篇关于GitHub 上的 origin 和 upstream 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆