在github上 一般我们都是将别人的repo fork到自己的github repo。 然后阅读,修改 甚至是contribution。所以同步源repo的commit 尤为重要。因为你要始终保持与源repo同步。下面将描述下怎么去同步更新的步骤。
1. 将源repo https link 加到自己本地 repo 的remote upstream中。添加之后,如果你想查看是否加入成功。可以使用git remote -v
git remote add upstream https://github.com/ORIGINAL_OWENER/ORIGINAL_REPO.git
2. fetch 源repo的最新提交到本地, 然后merge到自己的repo
git fetch upstream
git checkout master #if you current branch isn't master
git merge upstream/master
Or use following one command replace above three commands
git pull upstream master
#upstream represents remote source repo
#master represents master branch of the forked repo
3. 将自己repo的合并后的,提交到github上。
git push origin master
Note: 如何强制 覆盖github上的commit
# add -f is ok
git push -f origin master