Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone multiple git repositories in one local directory?

Tags:

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?

like image 282
vir2al Avatar asked Sep 19 '13 16:09

vir2al


2 Answers

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.

like image 85
Fábio Correia Avatar answered Sep 27 '22 16:09

Fábio Correia


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.

https://raw.githubusercontent.com/bl4ckbo7/agt/master/screenshots/agt_clone1.png

like image 31
VonC Avatar answered Sep 27 '22 18:09

VonC