git 更新远程仓库至folk仓库

2020-07-07  本文已影响0人  dc的梦呓

如下情形:在github上fork的一个仓库remote-rep到自己的仓库下remote-rep1,clone remote-rep1到本地目录下进行修改,修改后push到remote-rep1。若原始仓库remote-rep更新了,想要把这些更新也更新到自己的仓库中remote-rep1。可进行如下操作:

# 添加远程仓库,可称为 upstream
git remote add upstream https://github.com/[source]/remote_rep.git

# 获取远程仓库的更新
#Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream

# Make sure that you're on your master branch:
git checkout master

# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:
git rebase upstream/master

更新完后,再将本地仓库的修改后推送至remote-rep1:

#only need to use the -f the first time after you've rebased
git push -f origin master

参考资料
https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository

上一篇下一篇

猜你喜欢

热点阅读