gitee fork 源作者更新后如何同步更新且不覆盖自己的代码

以https://gitee.com/dromara/RuoYi-Vue-Plus为例

如果从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 就好了。

posted @ 2026-02-05 11:38  疯狗强尼  阅读(12)  评论(0)    收藏  举报