如何将一个git仓库中的单独分支复制到另一个git仓库?

10

我正在使用以下步骤将所有分支复制到新的存储库中。

git clone --bare https://github.com/exampleuser/old-repository.git
# Make a bare clone of the repository

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
# Mirror-push to the new repository

现在,我已经在 old-repository.git 中添加了两个新的分支,想要将这两个分支移动到 new-repository.git 中。

需要执行哪些 Git 命令来完成它?


我没有确切的答案,但是您想仅移动两个分支的动机是什么? - Tim Biegeleisen
我正在从 old-repo 迁移到 new-repo。除了 old-repo 中新创建的 2 个分支外,我已经将所有分支移动到 new-repo - meallhour
也许你可以尝试将这些新分支推送到另一个仓库,参见此处 - Tim Biegeleisen
3个回答

19
您可以将 new_repo 添加为旧存储库的远程存储库:这样更方便推送。
cd old_repo
git remote add new /path/to/new/repo
git push new newBranch1
git push new newBranch2

6

克隆旧分支

git clone --single-branch --branch branch_name github_repo_url

告诉git你的仓库所在位置:
git remote add mine your_repo_url

然后,使用以下命令将分支推送到您的存储库中:
git push -u mine

你不必克隆你的代码库,你可以直接从旧代码库指向新代码库。 - VonC

0

cd old_repo
git remote add new <新的 Git 仓库克隆链接>
git push new branchName


这不就是五年前我在我的回答中提到的吗? - VonC
已经有一个被接受的答案了,这是重复的。 - Daniel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接