如何克隆特定的Git分支?

编程入门 行业动态 更新时间:2024-10-16 20:29:49
本文介绍了如何克隆特定的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分支?

本文发布于:2023-07-17 02:49:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支   Git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!