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 格式 | 特点 |
|---|---|---|
| HTTPS | https://github.com/user/repo.git | 简单通用,需输入密码 |
| SSH | git@github.com:user/repo.git | 需配置密钥,免密操作 |
| Git | git://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 远程源。
要点总结
git clone <url>克隆远程仓库到本地- 支持 HTTPS、SSH、Git 协议
--depth 1浅克隆,节省空间和时间-b <branch>克隆指定分支- 克隆后自动设置 origin 远程源
📝 发现内容有误?点击此处直接编辑