- 检查当前远程仓库的路径。
$ git remote -v
origin https://github.com/chenhui0212/hll-api-navigator.git (fetch)
origin https://github.com/chenhui0212/hll-api-navigator.git (push)
- 添加原仓库。
$ git remote add upstream https://github.com/JetBrains/intellij-platform-plugin-template.git
- 再次查看远程仓库的路径。
$ git remote -v
origin https://github.com/chenhui0212/hll-api-method-navigator.git (fetch)
origin https://github.com/chenhui0212/hll-api-method-navigator.git (push)
upstream https://github.com/JetBrains/intellij-platform-plugin-template.git (fetch)
upstream https://github.com/JetBrains/intellij-platform-plugin-template.git (push)
- 拉取原仓库代码(更新亦可)。
$ git fetch upstream
warning: 没有共同的提交
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 814 (delta 26), reused 37 (delta 15), pack-reused 759
接收对象中: 100% (814/814), 822.41 KiB | 363.00 KiB/s, 完成.
处理 delta 中: 100% (427/427), 完成.
来自 https://github.com/JetBrains/intellij-platform-plugin-template
* [新分支] main -> upstream/main
* [新标签] v0.0.2 -> v0.0.2
...
* [新标签] v0.3.4 -> v0.3.4
- 合并原仓库分支。
$ git merge upstream/main
fatal: 拒绝合并无关的历史
- 如果出现如上信息,可以添加
--allow-unrelated-histories
参数进行合并。
$ git merge --allow-unrelated-histories upstream/main
- 如果存在冲突,这里需要手动解决,最后推送合并之后的分支。
$ git push
网友评论