This is a super annoying problem that pops up when I am cloning large repositories and my connection is a bit slow.
Part way through the clone git will fail.
FATAL ERROR: Remote side unexpectedly closed network connection fetch-pack: unexpected disconnect while reading sideband packet fatal: early EOF fatal: fetch-pack: invalid index-pack output
This fix on StackOverflow somewhat works for me if I do a set of fetch commands gradually increasing the checkout depth.
git clone --depth 1 $REPO_URI$
git fetch --deepen=32
git fetch --deepen=32
git fetch --deepen=32
git fetch --deepen=32
// etc. until an attempt at unshallow succeeds.
// experiment with the depth value (32/64/128/256/etc).
git fetch --unshallow