克隆clone github上某个项目的子目录

有时会遇到只需要克隆github某个项目的子目录,此时可以使用以下方法实现:

需求示例:

现需要克隆:https://github.com/SingleZombie/DL-Demos项目中的ddim项目

注:ddim项目的地址为:https://github.com/SingleZombie/DL-Demos/tree/master/dldemos/ddim

Step1: git clone --filter=blob:none --no-checkout https://github.com/SingleZombie/DL-Demos
Step2: cd DL-Demos, 即表示进行到该目录
Step3: git sparse-checkout init --cone
Step4: git sparse-checkout set dldemos/ddim, 其中dldemos/ddim表示https://github.com/SingleZombie/DL-Demos这个目录下的相对路径
Step5: git checkout master, 其中master表示分支,可以在github项目中查看,如下图所示:

详细的代码步骤如下:

复制代码
git clone --filter=blob:none --no-checkout https://github.com/SingleZombie/DL-Demos
cd DL-Demos
git sparse-checkout init --cone
git sparse-checkout set dldemos/ddim
git checkout master
相关推荐
kidwjb1 小时前
信号量在进程中的使用
linux·进程间通信
小猴小猴3 小时前
GitHub本周热门项目(2026-05-18)
github
sulikey3 小时前
个人Linux操作系统学习笔记2 - gcc与库的理解
linux·笔记·学习·操作系统·gcc·
二宝哥3 小时前
Linux虚拟机网络配置
linux·运维·服务器
陳10304 小时前
Linux:进程间通信 和 简单进程池
linux·运维·服务器
jimy14 小时前
改.bashrc,直观地判断本地repo是否有改动
linux·服务器
愚昧之山绝望之谷开悟之坡4 小时前
什么是Linter?什么是沙箱!
linux·笔记
babytiger5 小时前
Gitea 重安装 + Snap 数据迁移完整流程总结
linux·elasticsearch·gitea
匆匆那年9675 小时前
远程 Linux 校园网认证操作手册(本地浏览器法)
linux·运维·服务器
newnazi5 小时前
RedHat10 安装MS SQL Server2025
linux·服务器·数据库