Skip to content

Instantly share code, notes, and snippets.

@knownothingsnow
Created October 16, 2020 11:13
Show Gist options
  • Save knownothingsnow/a3e417a02fe9835c464b1f68709ac870 to your computer and use it in GitHub Desktop.
Save knownothingsnow/a3e417a02fe9835c464b1f68709ac870 to your computer and use it in GitHub Desktop.
通过 www.gitclone.com 加速 github clone
,gitclone(){
if [[ "$1" =~ ^git@github.com ]]; then
local repo=$(echo $1 | grep -Po '(?<=git@github\.com:)[\w-]+\/[\w-]+')
local origin_url=$1
elif [[ $1 =~ ^https://github.com ]]; then
local repo=$(echo $1 | grep -Po '(?<=https:\/\/github\.com\/)[\w-]+\/[\w-]+')
local origin_url=$1
elif [[ $1 == "gh" ]]; then
local repo=${4}
local origin_url="git@github.com:$repo.git"
else
echo "Url isn't vaild."
fi
local repo_name=$(echo $repo | grep -Po '(?<=\/)[\w-]+')
local new_url="https://gitclone.com/github.com/$repo.git"
echo "start downloading : ${repo}" && git clone $new_url
if [ -d $repo_name ] && [ $? == 0 ]; then
cd ./$repo_name && git remote rename origin mirror && git remote add origin $origin_url && cd -
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment