Skip to content
Go back

只克隆指定 Git 分支

Edit

默认 git clone 会把远程仓库的分支引用都拉下来。只想要某一个分支时,加上 --single-branch。参考:How to Clone a Specific Git Branch Without Other Branches

只克隆指定分支

git clone --single-branch --branch <branch_name> <repo_URL.git>

例如只拉 Kubernetes 的 release-1.28

git clone --single-branch --branch release-1.28 https://github.com/kubernetes/kubernetes.git

再只要最新一次提交

仓库很大、只需要当前代码时,加上 --depth 1,克隆更快、体积更小:

git clone --single-branch --branch <branch_name> --depth 1 <repo_URL.git>
git clone --single-branch --branch release-1.28 --depth 1 https://github.com/kubernetes/kubernetes.git

浅克隆之后如果要完整历史,可以再执行 git fetch --unshallow


Edit
Share this post on:

Previous Post
只拉取指定目录更新
Next Post
Git 忽略文件的三种方式