如何克隆特定的 Git 分支?

编程入门 行业动态 更新时间:2024-10-17 09:49:28
本文介绍了如何克隆特定的 Git 分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Git clone 会将远程分支克隆到本地.

Git clone will clone remote 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 ;url 你正在获取所有分支并检查一个.例如,这可能意味着您的存储库有一个 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:48:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支   Git

发布评论

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

>www.elefans.com

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