克隆只有一个分支

我想知道如何克隆只有一个分支,而不是克隆整个Git存储库。

从公告Git 1.7.10 (2012年4月):

  • 学习git clone --single-branch选项限制克隆到一个单一的分支(惊喜! 没有指向分支历史logging的标签不会被提取。

Git实际上只允许你克隆一个分支,例如:

 git clone -b mybranch --single-branch git://sub.domain.com/repo.git 

注意 : 您也可以添加另一个单独的分支或“撤消”此操作。

你可以创build一个新的回购

 git init 

然后使用

 git fetch url-to-repo branchname:refs/remotes/origin/branchname 

把这个分支拿到本地的远程跟踪分支。

– 单支 ”开关是你的答案,但它只适用于你的git版本1.8.X以上,首先检查

 #git --version 

如果你已经安装了git 1.8.X版本,那么只需使用“-b branch和–single branch”克隆一个分支

 #git clone -b branch --single-branch git://github/repository.git 

默认情况下,在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 

一旦1.8.X被安装,现在简单地做:

 git clone -b branch --single-branch git://github/repository.git 

Git现在只能从服务器下载一个分支。

我已经完成了下面的单一的git命令:

 git clone [url] -b [branch-name] --single-branch