4

Hey I have a shell script that git clone a repo in one of its steps,

But I noticed that git clone fails ramdomly, do we have anyway to retry when such random issue occur?

git clone https://xxxxxx.git Cloning into 'xxxx'... error: RPC failed; result=56, HTTP code = 200 fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed

12f0af0
  • 105
  • 2
  • 11
  • [This](http://stackoverflow.com/questions/35014012/git-retry-if-http-request-failed) may be able to help you, or alternatively [this](http://stackoverflow.com/questions/8587536/is-there-any-way-to-continue-git-clone-from-the-point-where-it-failed). Give that a try. – willyb321 Jun 16 '16 at 03:43
  • Note: a git clone for a repo with submodule will always try to clone a submodule *twice* (one retry). See "[Is there any way to continue Git clone from the point where it failed?](http://stackoverflow.com/a/38329327/6309)". – VonC Jul 12 '16 at 12:49
  • it is weird to suggest this but.. I was tryiing to clone from github and it was ultra slow 10KB/s for unreal engine project, even if using --depth=1. What I had to do was to wait til 23h (south america at least) and the download speed went up to 1.5MB/s! so may be the answer is: insistence or patience, until they implement cloning resume/continue capability :P – Aquarius Power Aug 19 '21 at 02:06

2 Answers2

1

Check the return code of the clone operation. You could also parameterize the number of times to retry instead of hardcoding to 5 below. You may nor may not want the sleep below.

   n=0
   until [ $n -ge 5 ]
   do
      git clone "$1" && break
      n=$[$n+1]
      sleep 1
   done

Invoke this script and pass an argument of the repo URL

David Neiss
  • 8,161
  • 2
  • 20
  • 21
-1

Did you try using git protocol?

git clone git:// urls for git protocol.
George Poliovei
  • 1,009
  • 10
  • 12