gitee fork 源作者更新后如何同步更新且不覆盖自己的代码
以https://gitee.com/dromara/RuoYi-Vue-Plus为例
1 . 配置一个远程fork
-
给 fork 配置一个 remote
-
主要使用
git remote -v查看远程状态。
git remote -v
# origin https://gitee.com/gzhxd/RuoYi-Vue-Plus.git (fetch)
# origin https://gitee.com/gzhxd/RuoYi-Vue-Plus.git (push)
-
添加一个将被同步给 fork 远程的上游仓库
git remote add upstream https://gitee.com/dromara/RuoYi-Vue-Plus.git
-
再次查看状态确认是否配置成功。
git remote -v
# origin https://gitee.com/gzhxd/RuoYi-Vue-Plus.git (fetch)
# origin https://gitee.com/gzhxd/RuoYi-Vue-Plus.git (push)
# upstream https://gitee.com/dromara/RuoYi-Vue-Plus.git (fetch)
# upstream https://gitee.com/dromara/RuoYi-Vue-Plus.git (push)
2. 同步 fork
-
从上游仓库 fetch 分支和提交点,传送到本地,并会被存储在一个本地分支 upstream/master
git fetch upstream
git fetch upstream
# remote: Enumerating objects: 794, done.
# remote: Counting objects: 100% (300/300), done.
# remote: Compressing objects: 100% (60/60), done.
# remote: Total 794 (delta 215), reused 234 (delta 208), pack-reused 494 (from 1)
# Receiving objects: 100% (794/794), 4.00 MiB | 696.00 KiB/s, done.
# Resolving deltas: 100% (305/305), completed with 159 local objects.
# From https://gitee.com/dromara/RuoYi-Vue-Plus
* [new branch] 5.X -> upstream/5.X
* [new branch] dev -> upstream/dev
* [new branch] futuer/boot4 -> upstream/futuer/boot4
-
使用
git branch查看是否在主分支,如果没有在主分支,则切换到本地主分支git checkout master(由于https://gitee.com/dromara/RuoYi-Vue-Plus 的主分支名称为5.X所以用git checkout 5.X)
git checkout 5.X #
# Switched to branch '5.X'
-
把 upstream/master 分支合并到本地 master 上,这样就完成了同步,并且不会丢掉本地修改的内容。
git merge upstream/master
git merge upstream/5.X
-
如果想更新到 gitee的 fork 上,直接
git push origin master

浙公网安备 33010602011771号