背景: 在Gitee看到某個非常棒的項目, Fork到自己倉庫, 同時git clone 自己倉庫,用來自己開發, 后來初始Fork的項目更新了, 於是想更新初始Fork的最新代碼和已改的代碼整合起來..
首先在本地查看remote源, 可以看見初始本地倉庫副本的2個源
PS E:\workspace_idea\RuoYi-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_idea\RuoYi-Vue> git remote add upstream https://gitee.com/y_project/RuoYi-Vue.git
PS E:\workspace_idea\RuoYi-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_idea\RuoYi-Vue> git fetch upstream
From https://gitee.com/y_project/RuoYi-Vue
* [new branch] master -> upstream/master
切換到自己倉庫master分支,並合並upstream/master
PS E:\workspace_idea\RuoYi-Vue> git branch * master PS E:\workspace_idea\RuoYi-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_idea\RuoYi-Vue> git merge upstream/master Already up to date.
更新完后實現自己倉庫和Fork項目在自己本地了