git 只克隆一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4811434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clone only one branch
提问by max_
I would like to know how I could clone only one branch instead of cloning the whole Git repository.
我想知道如何只克隆一个分支而不是克隆整个 Git 存储库。
回答by shakaran
From the announcement Git 1.7.10(April 2012):
来自Git 1.7.10(2012 年 4 月)的公告:
git clone
learned--single-branch
option to limit cloning to a single branch (surprise!); tags that do not point into the history of the branch are not fetched.
git clone
--single-branch
将克隆限制为单个分支的学习选项(惊喜!);不会获取未指向分支历史记录的标签。
Git actually allows you to clone only one branch, for example:
Git 实际上只允许你克隆一个分支,例如:
git clone -b mybranch --single-branch git://sub.domain.com/repo.git
Note: Also you can add another single branch or "undo"this action.
注意:您也可以添加另一个分支或“撤消”此操作。
回答by Lily Ballard
You could create a new repo with
您可以创建一个新的回购
git init
and then use
然后使用
git fetch url-to-repo branchname:refs/remotes/origin/branchname
to fetch just that one branch into a local remote-tracking branch.
将那个分支提取到本地远程跟踪分支中。
回答by Waqas
“--single-branch” switch is your answer, but it only works if you have git version 1.8.X onwards, first check
“ --single-branch”开关是你的答案,但它只有在你有 1.8.X 版本的 git 时才有效,首先检查
#git --version
If you already have git version 1.8.X installed then simply use "-b branch and --single branch" to clone a single branch
如果您已经安装了 git 1.8.X 版本,那么只需使用“-b branch 和 --single branch”来克隆单个分支
#git clone -b branch --single-branch git://github/repository.git
By default in Ubuntu 12.04/12.10/13.10 and Debian 7 the default git installation is for version 1.7.x only, where --single-branchis an unknown switch. In that case you need to install newer git first from a non-default ppa as below.
默认情况下,在 Ubuntu 12.04/12.10/13.10 和 Debian 7 中,默认的 git 安装仅适用于 1.7.x 版,其中--single-branch是一个未知开关。在这种情况下,您需要首先从非默认 ppa 安装较新的 git,如下所示。
sudo add-apt-repository ppa:pdoes/ppa
sudo apt-get update
sudo apt-get install git
git --version
Once 1.8.X is installed now simply do:
现在安装 1.8.X 后,只需执行以下操作:
git clone -b branch --single-branch git://github/repository.git
Git will now only download a single branch from the server.
Git 现在只会从服务器下载一个分支。
回答by pRaNaY
I have done with below single git command:
我已经完成了以下单个 git 命令:
git clone [url] -b [branch-name] --single-branch