github 同步一个 fork
搜索 fork sync,就可以看到 GitHub 自己的帮助文档 Syncing a fork 点进去看这篇的时候,注意到有一个 Tip: Before you can sync your fork with an upstream repository, you must configure a remote that points to the upstream repository in Git.
根据这两篇文章,问题迎刃而解!
具体方法
Configuring a remote for a fork
给 fork 配置一个 remote
主要使用 (
git remote -v) 查看远程状态。git remote -v # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)添加一个将被同步给 fork 远程的上游仓库
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git再次查看状态确认是否配置成功。
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)
Syncing a fork
从上游仓库 fetch 分支和提交点(
git fetch upstream),传送到本地,并会被存储在一个本地分支 upstream/master切换到本地主分支(如果不在的话) (
git checkout master)把 upstream/master 分支合并到本地 master 上,这样就完成了同步,并且不会丢掉本地修改的内容。(
git merge upstream/master)如果想更新到 GitHub 的 fork 上,直接 (
git push origin master) 就好了。
Last updated
Was this helpful?