码迷,mamicode.com
首页 > 其他好文 > 详细

github中origin和upstream的区别(转)

时间:2015-09-08 23:15:26      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

 
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

github中origin和upstream的区别(转)

标签:

原文地址:http://www.cnblogs.com/softidea/p/4793254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!