git篇:仓库fork后怎么同步

fork仓库

git篇:仓库fork后怎么同步_第1张图片
此时会将该仓库在复制一份,并存放在你的路径下:
git篇:仓库fork后怎么同步_第2张图片

设置上游代码库

进入本地代码库:

king@king-server:~/workspace$ cd dubbo-admin/

king@king-server:~/workspace/dubbo-admin$ ls
cmd  conf  deploy  Dockerfile  docs  dubbo-admin-ui  go.mod  go.sum  hack  LICENSE  Makefile  NOTICE  pkg  README.md  README_ZH.md

查看远程仓库的路径

king@king-server:~/workspace/dubbo-admin$ git remote -v
origin  [email protected]:qiqiuyang/dubbo-admin.git (fetch)
origin  [email protected]:qiqiuyang/dubbo-admin.git (push)

这里可以发现从自己仓库clone下来后,fetch和push的路径都是自己的。

设置上游代码库

king@king-server:~/workspace/dubbo-admin$ git remote add upstream [email protected]:apache/dubbo-admin.git

再次查看远程仓库地址:

king@king-server:~/workspace/dubbo-admin$ git remote -v
origin  [email protected]:qiqiuyang/dubbo-admin.git (fetch)
origin  [email protected]:qiqiuyang/dubbo-admin.git (push)
upstream        [email protected]:apache/dubbo-admin.git (fetch)
upstream        [email protected]:apache/dubbo-admin.git (push)

同步源仓库的更新

使用下面的命令拉取源仓库的更新:

king@king-server:~/workspace/dubbo-admin$ git fetch upstream
remote: Enumerating objects: 1102, done.
remote: Counting objects: 100% (1047/1047), done.
remote: Compressing objects: 100% (400/400), done.
remote: Total 755 (delta 352), reused 670 (delta 285), pack-reused 0
Receiving objects: 100% (755/755), 491.02 KiB | 1021.00 KiB/s, done.
Resolving deltas: 100% (352/352), completed with 104 local objects.
From github.com:apache/dubbo-admin
 * [new branch]      dev-change-ui2antd -> upstream/dev-change-ui2antd
 * [new branch]      develop            -> upstream/develop
 * [new branch]      login              -> upstream/login
 * [new branch]      master             -> upstream/master
 * [new branch]      master-0.2.0       -> upstream/master-0.2.0
 * [new branch]      metadata           -> upstream/metadata
 * [new branch]      new-config-format  -> upstream/new-config-format
 * [new branch]      refactor-with-go   -> upstream/refactor-with-go
 * [new branch]      service-test       -> upstream/service-test
 * [new tag]         0.1                -> 0.1
 * [new tag]         0.3.0              -> 0.3.0
 * [new tag]         0.4.0              -> 0.4.0
 * [new tag]         0.5.0              -> 0.5.0

到这里就比较清晰了,在更新时就是把源仓库的更新的分支放在upstream下,例如:upstream/master

所以同步远端分支时,就是git fetch upstream,然后将自己的分支merge目标分支内容,例如:git merge upstream/master

如此便可以实现自己的fork仓库同步源仓库的新变更了。

你可能感兴趣的:(云原生,git,dubbo)