GitHub上fork别人的项目,并保存同步方法

18 篇文章 0 订阅
3 篇文章 0 订阅

fork别人项目,别人修改了同步到自己分支下

首先要先确定一下是否建立了主repo远程源:

git remote -v

如果里面只能看到你自己的两个源(fetchpush)

origin  git@github.com:pudoj/thingsboard.git (fetch)
origin  git@github.com:pudoj/thingsboard.git (push)

那就需要添加主repo的源:

git remote add thingsboard https://github.com/thingsboard/thingsboard.git
git remote -v
origin  git@github.com:pudoj/thingsboard.git (fetch)
origin  git@github.com:pudoj/thingsboard.git (push)
thingsboard https://github.com/thingsboard/thingsboard.git (fetch)
thingsboard https://github.com/thingsboard/thingsboard.git (push)

这里的thingsboard是我们建立的远程branch的一个本地别名。

注意: 一般有https或者ssh的方式,如果是ssh的方式,则需要添加ssh的URL,不能添加https的方式,否则不能在ssh下访问该URL,另外,如果想删除remote的thingsboard标签,则可以运行:

git remote rm thingsboard

然后你就能看到thingsboard了。

如果想与主repo合并:

git fetch thingsboard
git merge thingsboard/master

上面的步骤就已经可以将自己fork别人的项目同步更新了;

但是实际情况往往是fork别人的项目后,自己也会修改这个项目,当然原作者也会修改他自己的项目,此时的同步方法如下:

流程

  • fork 源仓库 — ① fork -->
  • fork 仓库副本 — ② clone -->
  • local 仓库

当你在远程端(如 Github)上 fork 了别人的一个仓库时,你的远程仓库将新建一份 fork 来的“仓库副本”。如果你想在本地修改这份副本仓库,你需要先 clone 它到本地:

$ git clone git@github.com:YOUR_USERNAME/YOUR_FORK# 
$ git clone https://github.com/YOUR_USERNAME/YOUR_FORK

现在你已经有了一份 fork的本地副本,同时你可以开始在本地修改代码了。

fork别人项目,自己也修改了,原作者也修改了,同步更新

流程:

  • fork 源仓库 —① fetch & merge–>
  • local 仓库 —② push–>
  • fork 仓库副本

到目前为止,你本地仓库的远程信息可以用

$ git remote -v

查看到:

https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

为了获得fork源仓库的更新,现在要添加 fork 源仓库的地址,例如:

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git

这里的thingsboard是可以修改名称的,代表 fork 源仓库的别名。

$ git remote -v

查看本地仓库关联的远程地址到:

origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
thingsboard https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git(fetch)
thingsboard https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (push)

以上设置好了,当你要更新 fork 源仓库的时候,首先 fetch 一份源仓库变动到本地,这回生成一个分支thingsboard/master

$ git fetch thingsboard

可以用查看分支命令查看所有分支:

$ git branch

然后,切换到本地 master 分支:

$ git checkout master

合并thingsboard/master
分支的变化到本地 master 分支:

$ git merge thingsboard/master

到这里,仅把 fork 源仓库更新到了本地仓库,如果想要更新远程端的 fork 仓库副本 ,必须向远程端 push 一次:

$ git push origin master

以上,fork 源仓库、fork 仓库副本 和 local 仓库实现了同步更新。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

junehappylove

急急如律令,buibui~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值