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

查看:29
本文介绍了如何克隆特定的 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 分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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