clone & fork, origin & upstream on GitHub

前言:繁忙的工作与学习之余,难免会对一些基础性的知识遗忘和混淆,不断的总结归纳,并以博文记录之,温故而知新,可以为帅岂。。。


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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值