Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github 使用经典问题:如何同步 fork 项目原仓库的更新 - 知乎 #89

Open
HenryTSZ opened this issue Nov 21, 2023 · 0 comments

Comments

@HenryTSZ
Copy link
Owner

Github 使用经典问题:如何同步 fork 项目原仓库的更新

Github 我们经常会通过 fork 开源项目在自己的仓库中更新,然后提交 Pull Request (Merge Request) 为开源项目做贡献。

不过我们经常会遇到原仓库更新,重新 fork 显然是不优雅的,那我我们该怎么同步更新呢?

如何在 Github 网页端同步更新?

  1. 进入你自己的 fork 过来的仓库。
  2. 点击 "Pull requests" ,如何点击右侧绿色的 "New pull request"。
  3. Github 首先会比较源仓库与你 fork 后的仓库,如果你没有做任何更改,则找不到要 PR 的内容。所以,我们需要点击 "switching the base",会将我们的仓库作为基础版本,原仓库作为 head 版本,现在我们会看到我们的需要需要 "catch up" 的更新。
  4. 点击 "Create pull request",起一个名字,然后点击 "Create pull request"。
  5. 点击 "Merge pull request",然后点击 "Confirm merge"。
  6. 如果我们没提交什么新代码,merge 过程将自动完成。

如何通过本地命令行同步更新?

  1. 验证远程分支可以 fetch 或 push
git remote -v

2. 指明我们需要同步的仓库

git remote add upstream https://github.com/OriginalRepo/OriginalProject.git

3. 验证

git remote -v

4. 拉取更新的 branches 和 commits

git fetch upstream

5. Checkout 本地分支

git checkout master

6. 合并

git merge upstream/master

7. 提交

git push origin master

Github 使用经典问题:如何同步 fork 项目原仓库的更新 - 知乎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant