GIT:仅从 GitHub 克隆特定分支 [英] GIT: Clone only specific branches from GitHub

查看:114
本文介绍了GIT:仅从 GitHub 克隆特定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种潜在的方法可以从 GitHub 克隆不完整的存储库,而只是克隆选定的分支?我发现使用命令可以进行单分支克隆:

Is there a potential way to clone not complete repository from GitHub, but just selected branches? I've found single branch clone is possible with command:

git clone git@github/path/to/repository.git --branch my_branch_1 --single-branch

git clone git@github/path/to/repository.git --branch my_branch_1 --single-branch

所以想实现这样的目标:

So would like to achieve something like this:

git clone git@github/path/to/repository.git --branch my_branch_1 --branch my_branch_2 --single-branch ??

git clone git@github/path/to/repository.git --branch my_branch_1 --branch my_branch_2 --single-branch ??

这意味着只有其中两个.问题是,这样的 repo 在 master 分支中非常庞大,开发人员不需要.他们只需要分支my_branch_1my_branch_2.开发人员应该从这些分支创建他们的 dev 分支,然后在 GitHub 上拉取请求master.

It means only two of them. The issue is, that such repo is quite huge in the master branch and not needed for developers. They just need branches my_branch_1 and my_branch_2. From such branches developers should make their dev branch and later pull request on GitHub to the master.

也许可以通过 git remote add 或类似的东西.但我可能不太熟悉 Git 内部的概念.

Maybe it's possible via git remote add or something like this. But I'm not so much familiar probably with the concept of Git internally.

推荐答案

似乎没有办法克隆多个分支,但是你可以只克隆一个,然后像这样fetch其余部分:

There doesn't seem to a way to clone multiple branches, but you can clone just one, then fetch the remainder like so:

git clone git@github/path/to/repository.git --branch my_branch_1 --single-branch
git fetch origin my_branch_2:my_branch_2 my_branch_3:my_branch_3

这篇关于GIT:仅从 GitHub 克隆特定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆