主要的步骤是先查看当前fork的远程代码库

1
2
3
git remote -v
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

然后添加一个上游代码库,地址就是之前被fork的那个代码库

1
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY

再次查看

1
2
3
4
5
git remote -v
origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

接着用如下命令获取上游代码并合并到当前工作区

1
2
3
git fetch upstream
git checkout master
git merge upstream/master

最后git push origin master即可完成提交。

发表评论