git clone 克隆仓库入门

一条命令把远程仓库连同完整历史下载到本地,立即开始开发。

Linux开发Git命令行低风险
运行 git clone https://github.com/example/project.git 然后 cd project,即可得到带完整提交历史的可用副本。

01命令

命令
$ git clone https://github.com/example/project.git && cd project

02作用说明

git clone 默认拉取所有分支和提交,并自动把远程命名为 origin,pull/push 开箱即用。网络慢或仓库很大时加 --depth 1 只拉最近一次提交(浅克隆),需要嵌套仓库再加 --recurse-submodules,想直接检出非默认分支用 --branch。使用 SSH 地址(git@github.com:user/repo.git)则用你的密钥认证,不用输令牌。

03风险

风险低风险
使用条件git package
!注意: 浅克隆(--depth)在补全历史之前无法正常 push,只适合浏览源码,打算提交代码的话不要用。

04撤销

撤销
$ rm -rf project

05来源

  • git-clone — Clone a repository into a new directory
    Git official documentation · community · 2026-09-17
    依据: Official docs describe cloning into a new directory, HTTPS/SSH URLs, and options --depth, --branch and --recurse-submodules; confirms 'git clone' and '--depth' appear in the text.
  • git-clone(1) — Debian man page
    Debian manpages · community · 2026-09-17
    依据: Man page documents 'git clone' usage with repository URL argument and the --depth option for shallow clones.

最后验证: 2026-09-19 · 分类: 开发者

06相关方案