跳转至

简介

git clone 是用于从远端代码服务器(比如github)下载远端仓库的基本指令。

基本用法

  • git clone url_of_remote_reporsitory

如果我需要下载https://github.com/zhoukaisspu/testing.git,则可以使用以下指令:

git clone https://github.com/zhoukaisspu/testing.git

shallow-clone

在某些情况下,我们的代码仓库可能因为多次的提交,导致仓库很大,每次clone会花费很长的时间及磁盘空间,这里 我们可以使用shallow-clone的方式,仅clone最新的提交, 而不是把每次的提交历史都clone下来,以此来提升clone的性能。

  • git clone [-b <branchName>] repository_url [--depth <depth>]

在上面的指令中我们通过:

  1. [-b <branchName>] 指定仅clone某个分支
  2. [--depth <depth>] 指定仅clone指定数量的commits

如果我需要从https://github.com/zhoukaisspu/testing.git下载master分支,且只需要最新的提交, 则可以使用以下指令:

git clone -b master https://github.com/zhoukaisspu/testing.git --depth 1