How do I clone a large Git repository on an unreliable connection?

后端 未结 6 769
悲&欢浪女
悲&欢浪女 2020-12-30 20:21

I want to clone LibreOffice. From the official website, this is what\'s written:

All our source code is hosted in git:

Clone: $ git clone gi

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 21:00

    The best method that I know of is to combine shallow clone (--depth 1) feature with sparse checkout, that is checking out only the subfolders or files that you need. (Shallow cloning also implies --single-branch, which is also useful.) See udondan's answer for an example.

    Additionally, I use a bash loop to keep retrying until finished successfully. Like this:

    #!/bin/bash
    
    git init 
    cd 
    git remote add origin 
    
    # Optional step: sparse checkout
    git config core.sparsecheckout true                     # <-- enable sparse checkout
    echo "subdirectory/*" >> .git/info/sparse-checkout      # <-- specify files you need
    
    # Keep pulling until successful
    until $( git pull --depth=1 origin master ); do         # <-- shallow clone
        echo "Pulling git repository failed; retrying..."
    done
    

    In this way I can eventually pull large repos even with slow VPN in China…

    Importantly, by pulling this way you will still be able to push.

提交回复
热议问题