两种方式:
提示:跟上游仓库同步代码之前,必须配置过 remote,指向上游仓库 。
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
打开命令行工具
切换当前工作路径至你的本地工程
从上游仓库获取到分支,及相关的提交信息,它们将被保存在本地的 upstream/master
分支
git fetch upstream
# remote: Counting objects: 75, done.
# remote: Compressing objects: 100% (53/53), done.
# remote: Total 62 (delta 27), reused 44 (delta 9)
# Unpacking objects: 100% (62/62), done.
# From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
# * [new branch] master -> upstream/master
切换到本地的 master
分支
git checkout master
# Switched to branch 'master'
把 upstream/master
分支合并到本地的 master
分支,本地的 master
分支便跟上游仓库保持同步了,并且没有丢失你本地的修改。
git merge upstream/master
# Updating a422352..5fdff0f
# Fast-forward
# README | 9 -------
# README.md | 7 ++++++
# 2 files changed, 7 insertions(+), 9 deletions(-)
# delete mode 100644 README
# create mode 100644 README.md
提示:同步后的代码仅仅是保存在本地仓库,记得 push
到 Github 哟。
步骤1
步骤二:这里一定要注意更新方向,是自己的仓库更新原仓库还是反过来。箭头代表方向,可以点击switching the base或者自己用鼠标选择更换箭头两边的仓库顺序,来切换更新方向。
步骤三
步骤四
这一页往下面拉:
原文:https://www.cnblogs.com/sxy370921/p/11734644.html