首页/开发/Git 与协作速查/git clone 克隆仓库
Git 基础与命令88 条

git clone 克隆仓库

把远端仓库复制到本地:自动配置 origin、拉取默认分支并建立跟踪关系,支持指定分支、目录名与子模块递归。

Git 与协作速查开发更新于 2026-10-12
用途从远端获取完整仓库
语法git clone [选项] <URL> [目录]
URL 形式https://、git@ssh、本地路径均可

常用示例

常用示例
git clone https://github.com/org/repo.git
git clone git@github.com:org/repo.git mydir
git clone -b release/2.x https://example.com/org/repo.git
git clone --recurse-submodules https://example.com/org/repo.git
clone 默认只是取回全部提交历史的一次性操作;后续同步用 git pull / fetch,不必重复克隆。

易错点

  • 把仓库克隆进另一个仓库目录会形成嵌套,提交时外层仓库可能把内层当成普通目录加入索引
  • 克隆大仓时断线重试会重新开始,可先用浅克隆 --depth 1 完成基线,再按需补历史

数据来源与参考

  • Git 官方文档:git-clone
  • Pro Git 2nd Edition · 2.1 取得 Git 仓库
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌