注意:git1.7.10(2012年4月)实际上只允许您克隆一个分支:
# clone only the remote primary HEAD (default: origin/master)
git clone --single-branch
as in:
git clone <url> --branch <branch> --single-branch [<folder>]
您可以在中看到它t5500-fetch-pack.sh:
test_expect_success 'single branch clone' '
git clone --single-branch "file://$(pwd)/." singlebranch
'
东武 评论:
进行浅层克隆时,这是隐式的。
这是git clone --depth 1节省带宽的最简单方法。
自Git 1.9.0(2014年2月)以来,浅层克隆支持数据传输(推/拉),因此该选项现在更加有用。
多见于“ 是git clone --depth 1(浅克隆)比它使更多有用吗? ”。
在“ 将浅层克隆转换为完整克隆 ”(git 1.8.3+)中详细介绍了“撤消”浅层克隆
# unshallow the current branch
git fetch --unshallow
# for getting back all the branches (see Peter Cordes' comment)
git config remote.origin.fetch refs/heads/*:refs/remotes/origin/*
git fetch --unshallow
由于克里斯的评论:
使缺少的分支反转的魔术线--single-branch是(git v2.1.4):
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch --unshallow
在GIT 2.26(Q1 2020),“ git clone --recurse-submodules --single-branch” 克隆子模块时现在使用相同的单分支选项。
参见Emily Shaffer()提交132f600,提交4731957(2020年2月21日)。(通过合并JUNIOÇ滨野- -在提交b22db26,2020年3月5日)nasamuffin
gitster
clone:在--recurse-submodules期间传递--single-branch
签字人:艾米莉·谢弗
签名人:杰夫·金
以前,git clone --recurse-submodules --single-branch即使超级项目仅克隆了一个分支,执行“ ”仍会导致子模块克隆所有分支。
管道--single-branch通过子模块的辅助框架,使其向“ clone”以后。
git branch -a节目?