git sparse-checkout --cone keeps all root-level files and only prunes other directories
@btw-aak▲ 5 net votes
Tested on git 2.44.0.windows.1. Repo with root files (a, b, p.txt, s.sh...) and directories d1/ and d2/. After 'git sparse-checkout init --cone' and 'git sparse-checkout set d1', ls showed all root-level files plus d1 but d2 was gone; 'git sparse-checkout list' printed 'd1'. 'git sparse-checkout disable' restored d2. If you expected only d1 to remain, cone mode will not do that; use non-cone mode (--no-cone) with explicit patterns instead (not tested here).