全部学科
NodeJS全栈
nodejs
Python全栈
python
小程序首页
📅 2026-05-11 6 分钟 ✍️ juanwangdev

git clone 克隆仓库

git clone 命令将远程仓库完整复制到本地,包含所有历史记录。

基本用法

Bash
# 克隆远程仓库
git clone <url>

# 克隆到指定目录名
git clone <url> <directory>

# 克隆 GitHub 仓库
git clone https://github.com/user/repo.git
git clone git@github.com:user/repo.git

克隆示例

Bash
# HTTPS 方式
git clone https://github.com/vuejs/vue.git

# SSH 方式
git clone git@github.com:vuejs/vue.git

# 指定目录名
git clone https://github.com/vuejs/vue.git my-vue

克隆方式对比

方式URL 格式特点
HTTPShttps://github.com/user/repo.git简单通用,需输入密码
SSHgit@github.com:user/repo.git需配置密钥,免密操作
Gitgit://github.com/user/repo.git只读,较少使用

常用选项

Bash
# 浅克隆(只取最近一次提交,节省空间)
git clone --depth 1 <url>

# 克隆指定分支
git clone -b <branch> <url>

# 克隆到指定目录
git clone <url> <directory>

# 裸克隆(无工作区)
git clone --bare <url>

克隆后目录结构

Bash
project/
├── .git/          # Git 仓库目录
├── .gitignore     # 忽略规则文件
├── README.md      # 说明文件
└── src/           # 源代码目录

克隆会自动创建远程仓库名的同名目录,并自动设置 origin 远程源。

要点总结

  1. git clone <url> 克隆远程仓库到本地
  2. 支持 HTTPS、SSH、Git 协议
  3. --depth 1 浅克隆,节省空间和时间
  4. -b <branch> 克隆指定分支
  5. 克隆后自动设置 origin 远程源

📝 发现内容有误?点击此处直接编辑

← 上一篇 git clean 清理未跟踪文件
下一篇 → git commit 提交更改
想查看更多题目和详细解析?
小程序提供完整的题库、模拟考试和详细解析
马上就来

长按或扫描二维码,立即体验

扫码体验小程序
马上就来
使用微信扫描二维码
立即体验完整题库