如何将多个 git 个仓库的分支合并为一个仓库的分支?

How to combine multiple git repos' branches as a single repo's branches?

我想整理我的 git 存储库,因为其中有多个存储库高度相关。现在我想将它们全部合并(而不是合并)到一个具有多个分支的单一回购协议中,并删除旧的回购协议。我该怎么办?

例如,我的仓库 A、B 和 C 的分支为 A.master、A.branch1、B.master、C.master、C.branch2。我想要的是创建一个新的 repo D,其分支是 D.master(新的东西),A.master(必须更改名称),A.branch1,B.master(必须更改名称) , C.master(必须更改名称),C.branch2 以及原始存储库中的所有提交历史记录。然后删除A、B、C,子模块就不能用了。

假设您有存储库 A、B 和 C,并且您创建了一个新的存储库 D。
假设您将被签出到您将合并的正确分支
例如。

$> cd A
$> git checkout master

然后将旧仓库分支的远程添加到新仓库

$> cd D
$> git remote add A "path to A"
$> git remote update

... 此时我只是复制粘贴这个答案 Merge git repo into branch of another repo

希望对您有所帮助。

您创建了一个名为 D 的新存储库。

  • 命令在 repo A
  • 中 运行
 1. git remote add repoD https://github.com/****/repod.git
 2. git checkout master (go to master branch of A)
 3. git co -b master_of_a
 4. git push -u repoD master_of_a

repeat the below steps for other branches in the repo A. Below example give for branch1 in the repo A

 1. git checkout branch1 (go to branch1 of A)
 3. git co -b branch1_of_a
 4. git push -u repoD branch1_of_a

  • 对所有回购和所有分支重复上述两个步骤。

是的。也存储提交历史