1、查看现有的远程仓库:
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
2、添加指向原仓库的upstream:
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
3、查看origin和upstream
$ 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)
4、直接从原仓库的master分支拉取代码并直接合并代码,其中pull=fetch+merge.
git fetch upstream/master
git reset --hard upstream/master
或者直接让本地master跟随:
git branch --set-upstream-to upstream/master
网友评论