Skip to content

Instantly share code, notes, and snippets.

@hz2
Created August 15, 2023 05:34
Show Gist options
  • Save hz2/36ba44c066bcbe80f0717ced8d155c73 to your computer and use it in GitHub Desktop.
Save hz2/36ba44c066bcbe80f0717ced8d155c73 to your computer and use it in GitHub Desktop.
clone repo from gitlab
#!/bin/bash
# clone repo from gitlab
# 1. copy link form the website
# a = [...document.querySelectorAll('.projects-list>li h2 a')].map(x=>x.href).join('\n')
# copy(a)
# 2. save to repo.txt
# 3. run the shell
# set curent directory
base=$PWD
while read line; do
# echo $line;
# read line from the file
# dirlast="$( echo $line | rev | cut -d'/' -f1 | rev )";
# cut the dir from the web url
dir="$(cut -d'/' -f4-99 <<<$line)"
# mkdir -p $dir
echo "==> Try to clone $line.git"
if [ ! -d $dir ]; then
git clone "$line.git/" $dir
else
echo "dir is exist"
fi
cd $dir
branch=$(git branch -r | tail -n +2)
for b in $branch; do
if git show-ref --quiet refs/heads/${b/origin\//}; then
echo "$b branch is exist"
else
echo $b
git checkout -t $b
fi
git pull
done
cd $base
done <repo.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment