git 将远程 github 存储库中的更改合并到本地存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/867831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:27:41  来源:igfitidea点击:

Merge changes from remote github repository to your local repository

gitmergerepositorygithub

提问by ?eljko Filipin

I have forked a repository on github some time ago, made a small change and pushed the change back to my github fork. The original repository has changed since. I would like to merge the changes from the original repository to my fork.

前段时间我在 github 上 fork 了一个仓库,做了一个小改动,把改动推回了我的 github fork。从那以后,原始存储库发生了变化。我想将原始存储库中的更改合并到我的 fork。

I am new to both git and github, and I need specific commands how to do it.

我是 git 和 github 的新手,我需要具体的命令来做这件事。

回答by ?eljko Filipin

git remote add {name} {Public Clone URL}
git pull {name} master
git push

Example:

例子:

git remote add bret git://github.com/bret/watir.git
git pull bret master
git push

回答by Marcin Gil

Simply add original repo as a remote and merge your fork with it; then push merged fork to github.

只需将原始 repo 添加为远程并将您的 fork 与其合并;然后将合并的 fork 推送到 github。

There's also a ruby gem for easier github operations. You can merge upstream with one call...

还有一个ruby gem 可以简化 github 操作。您可以通过一次呼叫合并上游...

回答by fat

Syncing a fork

同步分叉

(from GitHub Help)

(来自 GitHub 帮助)

https://help.github.com/articles/syncing-a-fork

https://help.github.com/articles/syncing-a-fork

回答by Val

git pull origin master

will do the job creating additional merge commit. If you do not have conflicts and do not want to create a rejoin (with additional 'merge' commit) for every commit that you push then rebaseis more preferred. You can do it with the Git Gui+gitk. Just fetch remote with Git Guithen open history with gitkand create temporary r_masterbranch at remotes/origin/masterfetched. Finally, call git rebase r_masterin the git bash. This will place your commits on top of the remote modifications. You are ready to push and remove the r_master.

将完成创建额外合并提交的工作。如果您没有冲突并且不想为您推送的每个提交创建重新加入(带有额外的“合并”提交),那么rebase更优选。你可以用 Git Gui+gitk 来完成。只需获取远程,Git Gui然后打开历史记录gitkr_masterremotes/origin/master获取时创建临时分支。最后,调用git rebase r_mastergit bash。这会将您的提交置于远程修改之上。您已准备好推送和删除r_master.

This commentsuggests that there are shortcuts for this flow.

评论表明此流程有捷径。