如何克隆特定的Git分支? [英] How do I clone a specific Git branch?

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

问题描述

Git克隆将表现出将远程当前工作分支复制到本地的行为.

Git clone will behave copying remote current working branch into local.

有没有办法自己克隆特定分支,而无需在远程存储库上切换分支?

Is there any way to clone a specific branch by myself without switching branches on the remote repository?

推荐答案

git clone --single-branch --branch <branchname> <remote-repo>

--single-branch选项从版本 1.7开始有效.10 及更高版本.

The --single-branch option is valid from version 1.7.10 and later.

另请参阅许多人喜欢的其他答案.

Please see also the other answer which many people prefer.

您可能还想确保您了解它们之间的区别.区别在于:通过调用git clone --branch <branchname> url,您将获取 all 个分支并签出一个分支.例如,这可能意味着您的存储库具有5kB文档或Wiki分支以及5GB数据分支.而且,每当您要编辑首页时,最终可能会克隆5GB的数据.

You may also want to make sure you understand the difference. And the difference is: by invoking git clone --branch <branchname> url you're fetching all the branches and checking out one. That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your frontpage, you may end up cloning 5GB of data.

同样,这并不是说git clone --branch并不是实现此目标的方法,只是当您询问克隆特定分支时,并非总是 您要实现的目标

Again, that is not to say git clone --branch is not the way to accomplish that, it's just that it's not always what you want to accomplish, when you're asking about cloning a specific branch.

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

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