bash script to clone/pull bulk git repo -
i've several(22) private repositories on gitlab
https
protocol , want checkout repositories providing username , password once bash script. can't seem make work. here's how far got: (any edit/optimization appreciated):
#!/bin/bash read -p "gitlab username: " user read -sp "gitlab password: " pass echo read -p "branch checkout: " branch echo repo[0]='.' #dir repo[1]='repo.myhost.com/project/app.git' #repo url repo[2]='plugins' repo[3]='repo.myhost.com/project/app-core.git' repo[4]='plugins' repo[5]='repo.myhost.com/project/plugin1.git' repo[6]='plugins' repo[7]='repo.myhost.com/project/plugin2.git' repo[8]='api-plugins' repo[9]='repo.myhost.com/project/api-plugin1.git' repo[10]='api-plugins' repo[11]='repo.myhost.com/project/api-plugin2.git' # add more repo total=${#repo[*]} echo "checking out repositories..." mkdir -p plugins mkdir -p api-plugins (( i=0; i<${total}; i+=2 )); dir=${repo[$i]} trepo="https://$user:$pass@${repo[$i+1]}" echo "checking out ${repo[$i+1]} directory $dir"... if cd $dir; git pull; else git clone -b branch --single-branch $trepo $dir; fi echo done
edit: git pull
doesn't provide password, don't know how that. password contains @
in it.
the outcome of script: asking username/pass again
mamun@linux ~/dev/projects $ ./checkout.sh git username: myuser git password: project branch: master checking out repositories... checking out repo.myhost.com/project/app.git directory .... username 'https://repo.myhost.com': ^c
as mentioned, password @
must percent encoded (as mention here).
in pure bash, see function instance.
try in same bash commands:
echo git ls-remote http://${user}:${pass}@repo.myhost.com/project/app.git git ls-remote http://${user}:${pass}@repo.myhost.com/project/app.git
the ls-remote query remote repo branches, without pulling or cloning: testing.
the op mamun sardar confirms in comments encoding issue , adds:
also made mistake should use:
git clone -b $branch
instead ofgit clone -b branch
i agree , recommend:
- using
${branch}
instead of$branch
. - checking script www.shellcheck.net
Comments
Post a Comment