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

How to copy only single branch from one git repo to another?

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

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 命令?

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

cd old_repo
git remote add new /path/to/new/repo
git push new newBranch1
git push new newBranch2

克隆旧分支

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

告诉 git 你的仓库在哪里:

git remote add mine your_repo_url

然后,将分支推送到您的仓库:

git push -u mine