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

In terms of source control, you're "downstream" when you copy (clone, checkout, etc) from a repository. Information flowed "downstream" to you.

When you make changes, you usually want to send them back "upstream" so they make it into that repository so that everyone pulling from the same source is working with all the same changes. This is mostly a social issue of how everyone can coordinate their work rather than a technical requirement of source control. You want to get your changes into the main project so you're not tracking divergent lines of development.

Sometimes you'll read about package or release managers (the people, not the tool) talking about submitting changes to "upstream". That usually means they had to adjust the original sources so they could create a package for their system. They don't want to keep making those changes, so if they send them "upstream" to the original source, they shouldn't have to deal with the same issue in the next release.

http://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream/2749166#2749166

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上进行fork操作 #### 创建Fork 当希望基于他人的项目创建自己的版本而不影响原项目时,可以使用Fork功能。通过点击目标仓库页面右上方的"Fork"按钮来启动此过程[^1]。 ```bash # 假设已经登录到GitHub账户 # 找到想要分叉的目标仓库主页 # 页面顶部右侧有明显的 "Fork" 按钮 ``` #### Clone Fork后的仓库至本地环境 完成上述步骤后,在个人账号下的新复制版库会看到该项目副本。此时可将其克隆下来以便于本地开发: ```bash git clone https://github.com/YourUsername/ForkedRepo.git cd ForkedRepo ``` #### 设置上游远程地址并与之同步更新 为了能够获取原始项目的最新改动,需配置指向源仓库的远端连接,并定期拉取最新的变更记录: ```bash # 添加名为 'upstream' 的远程链接指向官方主仓 git remote add upstream https://github.com/OriginalAuthor/OriginalRepo.git # 查看当前已设置的所有远程路径确认无误 git remote -v # 获取来自上级资源库的数据流但不自动合并入工作区 git fetch upstream # 将抓取的内容整合进指定分支内(通常为主干master) git merge upstream/master # 或者采用更简洁的一键式同步方式 git pull upstream master ``` #### 提交Pull Request贡献代码改进 经过一系列编辑调整之后准备向初始作者发起请求审核所作变动,则按照如下流程执行: ```bash # 创立新的特性专题分支开展具体任务前 git checkout -b feature-branch-name # 完成编码作业后再切换回默认发布线路上做最终集成测试 git checkout main || git checkout master # 把特色子项里的成果纳入主线之去 git merge feature-branch-name # 推送到云端服务器等待他人审阅反馈意见 git push origin HEAD ``` 最后一步就是在网页界面上找到对应位置提交PR给维护人员评估是否采纳这些变化了[^3]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值