Git sparse-checkout 检出指定目录或文件

# 1. 初始化空仓库
git init

# 2. 开启sparse-checkout 
git config core.sparsecheckout true

# 3. 设置过滤条件
echo xxx >> .git/info/sparse-checkout

# 4. 设置远程仓库地址
git remote add origin ssh://github.com/xxx.git

# 5. 拉取代码
git pull origin master

# 6. 添加其他目录(可选)
echo another_folder >> .git/info/sparse-checkout
git checkout master

# 7. 拉取所有不包含指定目录
echo /* >> .git/info/sparse-checkout
echo !xxx >> .git/info/sparse-checkout
git pull origin master

过滤规则:Git - git-sparse-checkout Documentation (git-scm.com)