背景: 在Gitee看到某个非常棒的项目, Fork到自己仓库, 同时git clone 自己仓库,用来自己开发, 后来初始Fork的项目更新了, 于是想更新初始Fork的最新代码和已改的代码整合起来..
首先在本地查看remote源, 可以看见初始本地仓库副本的2个源
PS E:workspace_ideaRuoYi-Vue> git remote -v origin https://gitee.com/easonstudy/RuoYi-Vue.git (fetch) origin https://gitee.com/easonstudy/RuoYi-Vue.git (push)
此时新增原始Fork项目源, 然后再查看remote源
PS E:workspace_ideaRuoYi-Vue> git remote add upstream https://gitee.com/y_project/RuoYi-Vue.git
PS E:workspace_ideaRuoYi-Vue> git remote -v
origin https://gitee.com/easonstudy/RuoYi-Vue.git (fetch)
origin https://gitee.com/easonstudy/RuoYi-Vue.git (push)
upstream https://gitee.com/y_project/RuoYi-Vue.git (fetch)
upstream https://gitee.com/y_project/RuoYi-Vue.git (push)
然后拉取upstream(Fork)代码,本地会有upstream/master分支
PS E:workspace_ideaRuoYi-Vue> git fetch upstream
From https://gitee.com/y_project/RuoYi-Vue
* [new branch] master -> upstream/master
切换到自己仓库master分支,并合并upstream/master
PS E:workspace_ideaRuoYi-Vue> git branch * master PS E:workspace_ideaRuoYi-Vue> git checkout master Already on 'master' Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) PS E:workspace_ideaRuoYi-Vue> git merge upstream/master Already up to date.
更新完后实现自己仓库和Fork项目在自己本地了