git 拉取远程仓库部分内容

648 阅读1分钟

问题

有时我们去 Git 上某个仓库拉取代码到本地开发,但并不需要整个仓库的内容,为了降低网络消耗和占用本地磁盘空间,所以可以只拉取部分代码

解决

假设我们想要去拉取 github.com/nvm-sh/nvm.… 仓库下的 test 文件夹到本地

1. mkdir nvm
2. cd nvm
3. git init  // 初始化本地 git 仓库
4. git remote add origin https://github.com/nvm-sh/nvm.git // 与远程仓库建立连接,关联远程仓库
5. git config core.sparsecheckout true // 开启Sparse Checkout模式
6. echo "test" >> .git/info/sparse-checkout // 设置需Check Out的文件。直接从项目目录下开始
7. git pull origin master