git clone --depth 1 快速拉取大型 Git 项目代码

当 GIT 项目庞大、分支众多、提交次数多时,你可能会发现 clone 项目的时间很长。

对于这种情况,其实我们在拉取代码时加上 --depth 1 即可大幅度提升拉取速度。--depth 1 让 clone 的项目只包含最近一次提交的一个分支,体积会小很多。
不过这种方法 clone 下来的内容不包含其他远程分支,如果希望切换分支,则可指定分支名称单独 fetch 下来。相关命令参考如下:

git clone --depth 1 https://github.com/lzwme/simple-mock.git
git remote set-branches origin 'remote_branch_name'
git fetch --depth 1 origin remote_branch_name
git checkout remote_branch_name
点赞 (2)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code