简体   繁体   中英

Creating a shell script to clone multiple git repositories and checkout a particular tag

I'm in need of a shell script which can read a file containing git repository URLs and the desired tag, clone the repository from the url & checkout the listed tag.

Example structure:

http://urlofgitrepohere/project.git:tag-number1

http://urlofgitrepohere/project.git:tag-number2

etc.

Any ideas?

Something like this should do the trick:

#!/bin/sh

while read line; do
  proto=$(echo $line | cut -f 1 -d :)
  url=$(echo $line | cut -f 2 -d :)
  url="${proto}:${url}"
  tag=$(echo $line | cut -f 3 -d :)
  repo=$(echo $url | cut -f 4 -d /)
  git clone $url && git --git-dir=$repo/.git checkout $tag
done < $1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM