首页 文章

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

提问于
浏览
285

GitHuboriginupstream 有什么区别?

完成 git branch -a 命令后,某些分支的前缀为 originremotes/origin/.. ),而其他分支的前缀为 upstreamremotes/upstream/.. ) .

1 回答

  • 567

    这应该在 GitHub forks (在本地克隆该fork之前在GitHub上分叉GitHub存储库)的上下文中理解 .

    • upstream 通常是指您已分叉的原始仓库
      (有关 upstream 术语的更多信息,另请参阅“Definition of “downstream” and “upstream””)

    • origin 是你的叉子:你自己在GitHub上的回购,克隆了GitHub的原始回购

    从GitHub页面:

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

    git remote add upstream git://github.com/user/repo.git
    

    您将使用 upstreamfetch from the original repo (以使本地副本与您要贡献的项目保持同步) .

    git fetch upstream
    

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

    您将使用 originpull and push ,因为您可以为自己的回购做出贡献 .

    git pull
    git push
    

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

    您将通过制作 pull request 回馈 upstream 回购 .

    fork and upstream

相关问题