如何仅将单个分支从一个git repo复制到另一个?

mea*_*our 3 git github repository bitbucket bitbucket-server

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

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
Run Code Online (Sandbox Code Playgroud)

现在,我在其中添加了两个新分支old-repository.git,只想将这两个分支移到new-repository.git

需要什么git命令来执行它?

Von*_*onC 7

您可以将new_repo添加为旧仓库的远程目录:这对于推送更加方便:

cd old_repo
git remote add new /path/to/new/repo
git push new newBranch1
git push new newBranch2
Run Code Online (Sandbox Code Playgroud)


mea*_*our 6

克隆旧分支

git clone --single-branch --branch branch_name github_repo_url
Run Code Online (Sandbox Code Playgroud)

告诉 git 你的仓库在哪里:

git remote add mine your_repo_url
Run Code Online (Sandbox Code Playgroud)

然后,使用以下命令将分支推送到您的仓库:

git push -u mine
Run Code Online (Sandbox Code Playgroud)