github中origin和upstream的区别(转)

Fork,本身并不是git工具中的一个命令,也不是对git的扩展,它是在GitHub上的概念,是另一种clone方式——在服务器端的clone
而我们通常意义上的clone,是将远程repo 复制一份到本地。

当你从GitHub上 clone 一个 repo 到本地时,除非你已明确声明是这个repo的contributor,否则你是不能向其pull request的,此时,该远程的repo对于本地repo来说,就是upstream。

当你从GitHub上 fork 一个 repo 之后,再 clone forked repo 到本地,你就可以任意向其pull request,此时,远程的 repo 就是 origin。

下面一段是来自 GitHub pages 的解释:

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/user/repo_name.git

总结下来: 
1. 如果是 upstream repo,你只可以拉取最新代码(即 git fetch ),从而保证你本地的仓库与源仓库同步 
2. 如果是 origin repo,就是你自己的repo(自己创建的,或者 fork 的项目)你可以做 任何推拉操作(pull and push) 
3. 你可以通过 pull request 向 upstream repo 贡献代码

Referenced by http://stackoverflow.com/questions/6286571/git-fork-is-git-clone

What is the difference between origin and upstream in github?

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

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

From the GitHub page:

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/user/repo.git

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).

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

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

http://my.oschina.net/uniquejava/blog/481625

时间: 2024-08-27 18:52:14

github中origin和upstream的区别(转)的相关文章

(转)如何将本地git仓库上传到GitHub中托管+实践心得

Git——新手入门与上传项目到远程仓库GitHub(转) - Chen_s - 博客园http://www.cnblogs.com/Chenshuai7/p/5486278.html 注意的问题: 1.当时在myeclipse里修改了代码,然后各种add,commit都改不了,找了半天原因,最后发现在myeclipse里加载的工程是一个复制品,就是git仓库里的原件并没有变化……好像之前为了让原件当做备份,我默认设置的是copy to meclipse中,所以在用myeclipse加载工程时要注

学习Git的一点心得以及如何把本地修改、删除的代码上传到github中

一:学习Github的资料如下:https://git.oschina.net/progit/ 这是一个学习Git的中文网站,如果诸位能够静下心来阅读,不要求阅读太多,只需要阅读前三章,就可以掌握Git的常用命令. 二:学习Git中远程仓库的问题: Git的远程仓库:就是管理你代码的地方,这个是Github中提供的有,只要你在Github中注册一下你就可以获得无限个Git的远程仓库. 我的Github中的远程仓库如下图所示: 对远程仓库我首先理解为:在Gitbash中敲一个命令:Git init

DOM 中 Property 和 Attribute 的区别

原文地址:http://web.jobbole.com/83129/ property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property是DOM中的属性,是JavaScript里的对象: attribute是HTML标签上的特性,它的值只能够是字符串: 基于JavaScript分析property 和 attribute html中有这样一段代码: <input

Github 中提交项目到自己仓库的gh-pages分支

Github 中提交项目到自己仓库的gh-pages分支 git symbolic-ref HEAD refs/heads/gh-pages git add -A git commit -m "no message" git push origin gh-pages 参考:https://www.cnblogs.com/MuYunyun/p/6082359.html 原文地址:https://www.cnblogs.com/hglibin/p/9977888.html

push到github中时被拒绝(rejected)error: failed to push some refs

在git push 后出项图片情况 出项该情况的原因是远程库和本地库内容有差异,可执行以下代码 git pull --rebase origin master 然后重新git push 即可上传到 github 中. 原文地址:https://www.cnblogs.com/amy2017/p/10088525.html

Git 常用命令 以及 如何将一个本地仓库托管到GitHub中

git init //初始化一个可以被Git管理的仓库 ls -ah //查看该目录下所有的文件列表(包括被隐藏的文件) git add readme.txt //将readme.txt文件添加到Git仓库中(在执行该命令之前需要在该目录下创建一个readme.txt文件) git commit -m "description content" //提交之前使用git add命令添加的文件,-m参数用来添加对本次提交的文件的描述 //可以在commit之前多次调用add添加多个文件,使

【翻译】JAVA中抽象类和接口的区别

不知道有没有人翻译过了,这篇是挺简单的,权当复习一遍内容吧. 很多常见的面试问题如"抽象类和接口有什么区别","你在什么时候用抽象类什么时候用接口".所以在这篇文章里面,我们会讨论一下这个话题. 在开始讨论它们的区别之前,我们先看看它们的介绍. Abstract class 抽象类 抽象类被用来抽象出子类的共同特征.它是不能被实例化的,它只能被子类继承作为超类使用.抽象类被用作它的子类下的层次结构创建模板(Abstract classes are used to c

lua中的pairs和ipairs区别

pairs Returns three values: the next function, the table t, and nil, so that the construction for k,v in pairs(t) do body end will iterate over all key–value pairs of table t. See function next for the caveats of modifying the table during its traver

浅谈HTTP中Get与Post的区别_转

可参考:HTTP请求中POST与GET的区别 Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP中的GET,POST,PUT,DELETE就对应着对这个资源的查,改,增,删4个操作.到这里,大家应该有个大概的了解了,GET一般用于获取/查询资源信息,而POST一般用于更新资源信息. 1.根据HTTP规范,GET用于信息获取,而且应该是安全的和幂等的