git clone/pull 仓库单个目录、文件夹


使用git的sparse-checkout. 步骤如下:

1、创建空仓库

mkdir my-prj && cd my-prj

git init  #初始化

2、拉取远程仓库信息

git remote add -f origin http://oauth2:your-token-here@your-git-repo-path.git # 获取远程仓库的文件和分支等信息

3、开启 sparse clone

git config core.sparsecheckout true  # 开启 sparse checkoout, 无--global, 仅对当前项目

4、设置过滤

echo "devops" >> .git/info/sparse-checkout # 设置过滤条件
echo "src/Package" >> .git/info/sparse-checkout # 设置过滤条件, 即需要clone的目录

5、更新仓库

git pull origin master # 拉取仓库

Git