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

后端 未结 6 768
悲&欢浪女
悲&欢浪女 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 <repo_dir>
    cd <repo_dir>
    git remote add origin <repo_url>
    
    # 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.

    0 讨论(0)
  • 2020-12-30 21:03

    You can do the following:

    git clone --depth 1 git@github.com:User/Project.git .
    git fetch --unshallow
    

    The first clone will still be atomic, so if your connection is not reliable enough to fetch the current HEAD then you will have trouble.

    The subsequent fetch should be incremental and retryable if the connection drops half-way though.

    0 讨论(0)
  • 2020-12-30 21:04

    The repository is accessible via the http protocol (aka dumb protocol) here: http://anongit.freedesktop.org/git/libreoffice/core.git.

    You can download everything here with wget or another download manager, and you'll have a clone of the repository. After that, you rename the directory from core.git to .git, and use the following command to tell git about the remote url:

    $ git remote add remote http://anongit.freedesktop.org/git/libreoffice/core.git
    $ git reset --hard HEAD
    
    0 讨论(0)
  • 2020-12-30 21:08

    Increase buffer size so that git can utilize your bandwidth properly. Use following commands.

    git config --global core.compression 0
    
    git config --global http.postBuffer 1048576000
    
    git config --global http.maxRequestBuffer 100M
    
    git clone <repo url>
    

    Wait till clone get complete.

    0 讨论(0)
  • 2020-12-30 21:10

    do 'git clone --depth 100' It should grab the last 100 commits

    0 讨论(0)
  • 2020-12-30 21:12

    I used a my web hosting server with shell access to clone it first and then used rsync to copy it locally. rsync would copy only remaining files when resumed.

    0 讨论(0)
提交回复
热议问题