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 git-fetch commands gradually increasing the checkout depth.
git clone --depth 1 --no-single-branch $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
It is important to include the --no-single-branch
arguement. Otherwise, git will only track the main branch and it's a fiddle to
get things setup to get all the remote branches when doing a git
fetch. StackOverflow has a
thread about the exact problem.