fork源码库以后如何同步最新的代码

1、先fork一个代码库到自己的仓库

比如: 我fork mybatis-3的源码库到自己的仓库(取名为:mybatis-3-note)
这个比较简单,点击fork按钮就行

2、fork的时候,只能fork源代码库的master分支,如何同步源代码库的所有内容到自己的仓库呢?

  • 在自己本地库设置关联源仓库
~/mygithub/mybatis-3-note  master ✔                                                                                                                  4d4h  ⍉
▶ git remote add upstream git@github.com:mybatis/mybatis-3.git

这里的upstream是自定义的名字,随便取名什么都行,目的是标记这个与源代码库建立关联

  • 然后执行命令 git remote -v 查看远程仓库的路径:
~/mygithub/mybatis-3-note  master ✔                                                                                                                   4d5h
▶ git remote -v
origin    git@github.com:xxx/mybatis-3-note.git (fetch)
origin    git@github.com:xxx/mybatis-3-note.git (push)
upstream    git@github.com:mybatis/mybatis-3.git (fetch)
upstream    git@github.com:mybatis/mybatis-3.git (push)

这里发现创建了一个叫做upstream的与源代码origin关联

  • 关联之后,就可以同步源代码库的其他分支到自己的仓库了,具体执行:git fetch [upstream自己前面定义的名字]
    原代码库分支名 : 本地代码库分支名,如同步mybatis-3源码库的3.4.x分支到我的代码库,并且也命名为3.4.x,执行命令:
    git fetch upstream 3.4.x:3.4.x
~/mygithub/mybatis-3-note  master ✔                                                                                                                  4d5h  ⍉
▶ git fetch upstream 3.4.x:3.4.x
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (16/16), done.
remote: Total 77 (delta 16), reused 16 (delta 16), pack-reused 61
Unpacking objects: 100% (77/77), done.
From github.com:mybatis/mybatis-3
 * [new branch]          3.4.x                  -> 3.4.x
 * [new tag]             mybatis-3.0.1          -> mybatis-3.0.1
 * [new tag]             mybatis-3.0.2          -> mybatis-3.0.2
 * [new tag]             mybatis-3.0.3          -> mybatis-3.0.3
 * [new tag]             mybatis-3.0.4          -> mybatis-3.0.4
 * [new tag]             mybatis-3.0.5          -> mybatis-3.0.5
 * [new tag]             mybatis-3.0.6          -> mybatis-3.0.6
 * [new tag]             mybatis-3.1.0          -> mybatis-3.1.0
 * [new tag]             mybatis-3.1.1          -> mybatis-3.1.1
 * [new tag]             mybatis-3.2.0          -> mybatis-3.2.0
 * [new tag]             mybatis-3.2.1          -> mybatis-3.2.1
 * [new tag]             mybatis-3.2.2          -> mybatis-3.2.2
 * [new tag]             mybatis-3.2.3          -> mybatis-3.2.3
 * [new tag]             mybatis-3.2.4          -> mybatis-3.2.4
 * [new tag]             mybatis-3.2.4-SNAPSHOT -> mybatis-3.2.4-SNAPSHOT
 * [new tag]             mybatis-3.2.5          -> mybatis-3.2.5
 * [new tag]             mybatis-3.2.5-SNAPSHOT -> mybatis-3.2.5-SNAPSHOT
 * [new tag]             mybatis-3.2.6          -> mybatis-3.2.6
 * [new tag]             mybatis-3.2.6-SNAPSHOT -> mybatis-3.2.6-SNAPSHOT
 * [new tag]             mybatis-3.2.7          -> mybatis-3.2.7
 * [new tag]             mybatis-3.3.0          -> mybatis-3.3.0
 * [new tag]             mybatis-3.3.0-SNAPSHOT -> mybatis-3.3.0-SNAPSHOT
 * [new tag]             mybatis-3.4.0          -> mybatis-3.4.0
 * [new tag]             mybatis-3.4.1          -> mybatis-3.4.1
 * [new tag]             mybatis-3.4.2          -> mybatis-3.4.2
 * [new tag]             mybatis-3.4.3          -> mybatis-3.4.3
 * [new tag]             mybatis-3.4.4          -> mybatis-3.4.4
 * [new tag]             mybatis-3.4.5          -> mybatis-3.4.5
 * [new tag]             mybatis-3.4.6          -> mybatis-3.4.6
 * [new tag]             mybatis-3.5.0          -> mybatis-3.5.0
 * [new tag]             mybatis-3.5.1          -> mybatis-3.5.1
 * [new tag]             mybatis-3.5.10         -> mybatis-3.5.10
 * [new tag]             mybatis-3.5.11         -> mybatis-3.5.11
 * [new tag]             mybatis-3.5.12         -> mybatis-3.5.12
 * [new tag]             mybatis-3.5.13         -> mybatis-3.5.13
 * [new tag]             mybatis-3.5.2          -> mybatis-3.5.2
 * [new tag]             mybatis-3.5.3          -> mybatis-3.5.3
 * [new tag]             mybatis-3.5.4          -> mybatis-3.5.4
 * [new tag]             mybatis-3.5.5          -> mybatis-3.5.5
 * [new tag]             mybatis-3.5.6          -> mybatis-3.5.6
 * [new tag]             mybatis-3.5.7          -> mybatis-3.5.7
 * [new tag]             mybatis-3.5.8          -> mybatis-3.5.8
 * [new tag]             mybatis-3.5.9          -> mybatis-3.5.9
 * [new branch]          3.4.x                  -> upstream/3.4.x

  • 或者直接执行 git fetch [upstream自己前面定义的名字] ,将源代码库的所有全部同步到自己的代码库
~/mygithub/mybatis-3-note  master ✔                                                                                                                   4d5h
▶ git fetch upstream

remote: Enumerating objects: 386125, done.
remote: Counting objects: 100% (198/198), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 386125 (delta 195), reused 198 (delta 195), pack-reused 385927
Receiving objects: 100% (386125/386125), 94.05 MiB | 1.93 MiB/s, done.
Resolving deltas: 100% (350860/350860), completed with 98 local objects.
From github.com:mybatis/mybatis-3
 * [new branch]            3.2.x                                          -> upstream/3.2.x
 * [new branch]            3.3.x                                          -> upstream/3.3.x
 * [new branch]            gh-pages                                       -> upstream/gh-pages
 * [new branch]            master                                         -> upstream/master
 * [new branch]            renovate/maven-org.hsqldb-hsqldb-vulnerability -> upstream/renovate/maven-org.hsqldb-hsqldb-vulnerability
 * [new tag]               mybatis-3.2.8                                  -> mybatis-3.2.8
 * [new tag]               mybatis-3.3.1                                  -> mybatis-3.3.1

这就同步到了原代码库的分支到自己的代码库。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值