Skip to content

Instantly share code, notes, and snippets.

@benizar
Last active May 3, 2024 21:45
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save benizar/03c5ede574ac7b847413857f74bb04b3 to your computer and use it in GitHub Desktop.
Save benizar/03c5ede574ac7b847413857f74bb04b3 to your computer and use it in GitHub Desktop.
Ubuntu post-installation script for cloning multiple git repositories.

multiple-git-clone.sh

Every time I install Ubuntu on a different computer, I need to clone again the same git repositories. This is why I use this bash script.

Usage

It clones the list of repositories to a convenient working directory in the home folder. I use the /home/git folder.

Arguments are lists of git repositories. One repo per line, one file per list. See the example:

git-project-1
git-project-2
git-project-3
...
git-project-n

This way you can execute the script passing one or many files as an argument

bash multiple-git-clone.sh *.list
#!/bin/sh
readarray array <<< $( cat "$@" )
mkdir -p ~/git && cd ~/git
for element in ${array[@]}
do
echo "clonning $element"
git clone $element
done
https://github.com/benizar/docker-library-template.git
https://github.com/benizar/docker-library.git
https://github.com/benizar/benizar.github.io.git
https://benizar@bitbucket.org/benizar/my-cv-factory.git
https://benizar@bitbucket.org/benizar/my-biblio-factory.git
https://github.com/siose-innova/siose-innova.github.io.git
https://github.com/siose-innova/siose-docker-library.git
https://github.com/siose-innova/pg_landmetrics.git
https://github.com/siose-innova/pg_geohash_extra.git
https://github.com/siose-innova/siose-splitter.git
@walterespino
Copy link

Thank you, this works great

@brajus
Copy link

brajus commented Sep 12, 2022

Thanks a lot, it worked amazingly!

@egenc
Copy link

egenc commented Sep 30, 2022

For a command that works in Mac OS, script.sh:

#!/bin/sh

for element in $(cat repo-list.txt)
do
  echo "clonning $element"
  git clone $element
done

Then run:
bash script.sh

@BlaneBlake
Copy link

Thank you !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment