Il costo dei clone completi
Un clone completo di un repository di lunga durata puo essere centinaia di megabyte. Su ogni job CI.
Basi del clone shallow
git clone --depth=1 https://example.com/repo.git
Shallow con piu branch
git clone --depth=1 --no-single-branch https://example.com/repo.git
Clone parziali (Git 2.22+)
git clone --filter=blob:none https://example.com/repo.git
git clone --filter=tree:0 https://example.com/repo.git
Combinare shallow e parziale
git clone --depth=1 --filter=blob:none https://example.com/repo.git
Esempio GitHub Actions
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get full history when needed
run: git fetch --unshallow
Limiti dello shallow
- Non si puo pushare da un clone shallow a un repo diverso senza unshallow.
- Alcune operazioni sono impossibili.
- Fork e setup complessi di submodule possono interagire male.
Misurare
time git clone --depth=1 https://example.com/repo.git
time git clone https://example.com/repo.git
Cachare il risultato
if [ -d .git ]; then
git fetch --depth=1
git reset --hard FETCH_HEAD
else
git clone --depth=1 ...
fi