git sparse-checkout

git の sparse-checkout を使ってモノリポでも快適にいこう! - asoview! Tech Blog 2023

cone

sparse-checkoutにはconeとnon-coneの2つのモードがある。標準ではconeモードが有効になっている。non-coneモードに切り替えるには--no-coneオプションをつける。

git sparse-checkoutで一部のファイルだけをチェックアウトする · Obsica 2022

cone

top-level ディレクトリのファイルは sparse-checkout の対象になる

$ git clone --filter=blob:none --no-checkout <git repository url>
$ cd <repository_name>

$ git sparse-checkout set directory1
$ cat .git/info/sparse-checkout 
/*
!/*/
/directory1/

$ git checkout
$ ls -1
README.md
directory1
no-cone

top-level ディレクトリのファイルを sparse-checkout の対象から外す場合は no-cone を使う

$ git clone --filter=blob:none --no-checkout <git repository url>
$ cd <repository_name>

$ git sparse-checkout set --no-cone /directory1/
$ cat .git/info/sparse-checkout 
/directory1/

$ git checkout
$ ls -1
directory1