Skip to content

Instantly share code, notes, and snippets.

@davidliyutong
Last active April 13, 2024 07:16
Show Gist options
  • Save davidliyutong/a37a07c7ad2115184e33c80801c0d66d to your computer and use it in GitHub Desktop.
Save davidliyutong/a37a07c7ad2115184e33c80801c0d66d to your computer and use it in GitHub Desktop.
Accelerate github clone by using mirror
# Clone github repo
# Usage:
#
# $ chmod +x ./github-fast-clone.sh
# $ ./github-fast-clone <user/repo>
#!/bin/bash
MIRROR=https://hub.fastgit.org/
GIT_HTTP_CONNECT_TIMEOUT=60
DEPTH=3
set +e
if [ $# -ge 1 ]; then
git clone https://github.com/$1 --depth $DEPTH
if [[ $? -ne $(expr 0) ]]; then
# In case of bad internet connection, use mirror
echo "Connection failed, using mirror"
git clone https://hub.fastgit.org/$1 --depth $DEPTH
fi
else
echo "Usage: ./git-fast-clone <user/repo>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment