git - 从原始 GitHub 存储库中 pull 新的更新到 fork 的 GitHub 存储库中

标签 git github

我在 GitHub 上 fork 了某人的存储库,并希望使用在原始存储库中进行的提交和更新来更新我的版本。这些是在我 fork 我的副本后制作的。

我怎样才能提取在源中所做的更改并将它们 merge 到我的存储库中?

最佳答案

您必须将原始存储库(您 fork 的那个)添加为远程。

来自GitHub documentation on forking a repository :

Screenshot of the old GitHub interface with a rectangular lens around the "Fork" button

Once the clone is complete your repo will have a remote named “origin” that points to your fork on GitHub.
Don’t let the name confuse you, this does not point to the original repo you forked from. To help you keep track of that repo we will add another remote named “upstream”:

$ cd PROJECT_NAME
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
$ git fetch upstream

# then: (like "git pull" which is fetch + merge)
$ git merge upstream/master master

# or, better, replay your local work on top of the fetched branch
# like a "git pull --rebase"
$ git rebase upstream/master

还有一个 command-line tool (gh) which can facilitate the operations above .

这是它如何工作的视觉图:

Flowchart on the result after the commands are executed

另请参阅“Are Git forks actually Git clones?”。

关于git - 从原始 GitHub 存储库中 pull 新的更新到 fork 的 GitHub 存储库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3903817/

相关文章:

git - merge 来自某个特定提交的两个 git 存储库

Git 推送错误 : unpack failed: index-pack abnormal exit

github - 我可以通过 Webhook 将应用程序部署自动化到 OpsWorks 吗?

GitHub 操作在 npm ci 上失败

php - 无法重新声明类 AbstractFindAdapter

git - 在 "export-subst"文件中添加标签

php - 如何处理 PHP 库中的配置文件

git - "git add -A :/"是做什么的?

git - Git Smart HTTP(S) 协议(protocol)在它所有的荣耀中是什么样子的?

python - github 不呈现 jupyter notebook python