Git 从另一个仓库拉取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24815952/
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 18:19:00  来源:igfitidea点击:

Git pull from another repository

gitversion-controlrepositorydvcs

提问by Libbux

I have a repository called Generic, which is a generic application. I have forked it into a repository called Acme, which just builds upon the application stored Genericrepository and adds Acme Co branding to it.

我有一个名为 的存储库Generic,它是一个通用应用程序。我已将其分叉到一个名为Acme的存储Generic库中,该存储库仅构建在应用程序存储库的基础上,并向其中添加了 Acme Co 品牌。

If I make changes to the core functionality in Generic, I want to update the Acmerepository with the latest changes I have made to the core functionality in Generic. How would I do that?

如果我修改的核心功能Generic,我想更新Acme与我已经到核心功能所做的最新更改存储库Generic。我该怎么做?

As far as I can tell, I am essentially trying to merge the changes made in an upstream repository into the current fork.

据我所知,我基本上是在尝试将上游存储库中所做的更改合并到当前分支中。

If it means anything, I'm trying to do this because I have a generic application that I then build upon and brand for individual clients (like Acmein this example). If there is a cleaner way of doing this, let me know.

如果这意味着什么,我正在尝试这样做,因为我有一个通用应用程序,然后我可以为各个客户构建和品牌化(就像Acme在这个例子中一样)。如果有更干净的方法来做到这一点,请告诉我。

回答by McLovin

Issue the following command in your Acmerepo. It adds a new remote repository named upstreamthat points to the Genericrepo.

在您的存储Acme库中发出以下命令。它添加了一个新的远程存储库,名为upstream指向该存储库Generic

git remote add upstream https://location/of/generic.git

You can then merge any changes made to Genericinto the current branch in Acmewith the following command:

然后,您可以使用以下命令将所做的任何更改合并Generic到当前分支中Acme

git pull upstream

If you just want it to download the changes without automatically merging, use git fetchinstead of git pull.

如果您只想下载更改而不自动合并,请使用git fetch代替git pull

If you want to disable pushing to that repository, set the push URL to an invalid URL using something like

如果要禁用推送到该存储库,请使用类似的方法将推送 URL 设置为无效 URL

git config remote.upstream.pushurl "NEVER GONNA GIVE YOU UP"

Git will now yell at you about not being able to find a repo if you try to push to upstream(and sorry about the Rickroll, but it was the first random string that popped into my head).

如果您尝试推送,Git 现在会因为无法找到存储库而对您大喊大叫upstream(对 Rickroll 感到抱歉,但这是第一个出现在我脑海中的随机字符串)。

回答by vin

In order to pull a particular branch from different repo you can use the below git command.

为了从不同的 repo 中提取特定分支,您可以使用以下 git 命令。

git pull <git_url> <branch> --allow-unrelated-histories