上周上MHRI的时候把fork过来的仓库clone到了本地,今天需要把原仓库更新的内容同步过来,直接在网站上操作的话只能放弃之前的commits,所以这里记录一下怎么在本地操作.
0 查看远程仓库信息
1 2 3
| % git remote -v origin git@github.com:fulcrum-zou/Mobile_HRI_Lab_Hub.git (fetch) origin git@github.com:fulcrum-zou/Mobile_HRI_Lab_Hub.git (push)
|
1 将原仓库添加到remote
取名为upstream.
1
| % git remote add upstream git@github.com:FAR-Lab/Mobile_HRI_Lab_Hub.git
|
查看是否添加成功.
1 2 3 4 5
| % git remote -v origin git@github.com:fulcrum-zou/Mobile_HRI_Lab_Hub.git (fetch) origin git@github.com:fulcrum-zou/Mobile_HRI_Lab_Hub.git (push) upstream git@github.com:FAR-Lab/Mobile_HRI_Lab_Hub.git (fetch) upstream git@github.com:FAR-Lab/Mobile_HRI_Lab_Hub.git (push)
|
2 同步fork
从原仓库fetchbranch和commits并传送到本地,此时被存储在了本地分支upstream/main中.
1 2 3 4
| % git fetch upstream ... * [new branch] Archive -> upstream/Archive * [new branch] main -> upstream/main
|
确保切换到了本地分支.
1 2 3
| % git checkout main Already on 'main' Your branch is up to date with 'origin/main'.
|
3 合并分支
把upstream/main合并在本地的master上
1 2 3 4
| % git merge upstream/main Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.
|
发现有冲突.
如果没有冲突可以跳过第4步.
4 合并冲突
1 2 3
| % git add . % git commit -m "Merge conflicts" [main 43683b1] Merge conflicts
|
5 推送到远程仓库
6 下次更新
直接从第2步开始.
参考
[1] git fork解决冲突