拉取多个存储库后如何保留分支

How do I preserve branches after pulling multiple repositories

我正在尝试将多个存储库合并到一个存储库中。但在 git pull <URL> 存储库合并后,无法识别各个存储库中确实存在的分支。

对于这种情况,您应该查看 Git Submodules。这基本上就是答案(抱歉,实际上只是 link,但它本身就是一个完整的主题)

这将允许您使用多个存储库创建一个代码库,并将每个子模块设置为自己的版本。

子模块文档的介绍是:

It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects. A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other.

这听起来与您要在此处实现的目标完全一样。

文档中给出的示例显示了如何创建它:

$ git submodule add https://github.com/chaconinc/DbConnector
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.

这还应该创建一个 .gitmodules 文件,其中列出了正在使用的子模块。