Is it possible to git clone
multiple git repositories with one command (for example: git clone "1.git,2.git,3.git.."
in one local directory?
This is how almost solved for myself:
git clone https://myrepo.com/folder.git && \ git clone https://myrepo.com/folder2.git && \ git clone https://myrepo.com/folder3.git
This is way easier to build using a code editor like Sublime or VSCode.
The only downside for me: If you did not store your credentials, you're gonna have to type it over and over.
You can find script example like this one:
I have this file called "clone" containing URLs of several git repos (taken from djangosites.com. Awesome site. Must visit)
Snippet:
$ cat clone https://github.com/igorsobreira/igorsobreira.com https://github.com/ella/ella https://github.com/divio/django-cms/ https://github.com/palewire/palewire.com https://github.com/jabapyth/jfcom https://github.com/humanfromearth/snippify https://github.com/scaphilo/koalixcrm https://github.com/jlev/Boycott-Toolkit https://github.com/jbalogh/zamboni/ https://github.com/ASKBOT/askbot-devel https://github.com/emesik/djiki https://github.com/vicalloy/LBForum https://github.com/agiliq/agiliq https://github.com/bartTC/dpaste.de https://github.com/bartTC/django-paste https://github.com/bartTC/dpaste_de/ https://github.com/fotochest/fotochest https://esp.mit.edu/git/esp-project.git https://github.com/titan2x/bashoneliners.git
Apparently, it's harder to clone multiple repos at once (
git clone <repo1> <repo2> ... <repon>
does not work). So I wrote this short bash code to make it work:Code:
atm in /home/atm/git/django_repos $ for f in `cat clone`; do `git clone $f`; done
You would find many more on gist.github.com, like this one, to clone all your repos from GitHub:
#!/bin/bash # # Copyright 2011, Tim Branyen @tbranyen <[email protected]> # Dual licensed under the MIT and GPL licenses. # # Automatically clone single or multiple repos into a folder, # great for setting up a git projects folder. # # Install: curl https://gist.github.com/raw/902154/github.sh > /usr/local/bin/gh # chmod +x /usr/local/bin/gh # # Internal properties [email protected]: GITHUB_USERNAME=$(git config --global github.user) function main { # Improperly configured user detect_user # Missing arguments args=$1 if [ -z $args ]; then echo ' gh: try ''`gh --help`'' for more information ' exit fi # Display help text if [ $args = '--help' ]; then echo ' Clone repos from your GitHub gh repo1 repo2 Clone repos from others GitHub gh username/repo1 username/repo2 Clone mixed repos: gh repo1 username/repo2 Clone line separated repos from file: cat file | xargs gh ' exit fi # Parse arguments and clone repos. find_repos } function detect_user { # If no username configured, attempt to pull from git --config if [ -n "$GITHUB_USERNAME" ]; then USERNAME=$GITHUB_USERNAME else echo ' gh: missing username configure username with ''`git config --global github.user username`'' ' exit fi } function find_repos { for repo in $args; do # If a user provides the parameter username/repo pull in that specific repository. if [ `awk -v repo="$repo" -v delimit="/" 'BEGIN{print index(repo,delimit)}'` -ne 0 ]; then echo "Pulling in $repo"; git clone $GITHUB_PREFIX$repo.git # Default to you. else echo "Pulling in $USERNAME/$repo"; git clone $GITHUB_PREFIX$USERNAME/$repo.git fi done } main $*
More generally, a scripting approach is needed, and lilgeek
mentioned bl4ckbo7/agt, a python script which includes cloning with fastest and parallel clone processing feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With