在一个本地目录签出多个git存储库? [英] Checkout multiple git repositories in one local directory?

查看:131
本文介绍了在一个本地目录签出多个git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用一个命令(例如:git clone1.git,2.git,3.git ..在一个本地目录中git clone多个git存储库?





解决方案

您可以找到像 this one


我有一个名为clone的文件,其中包含几个git repos的URL(摘自 djangosites.com

片段:




  $ 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:// gi thub.com/jbalogh/zamboni/ https://github.com/ASKBOT/askbot-devel https://github.com/emesik/djiki https://github.com/ cervicalloy/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/es​​p-project.git https://github.com/titan2x/bashoneliners.git




显然,一次克隆多个回购很难( git clone< repo1> < repo2> ...< repon> 不起作用)。所以我写了这个简短的bash代码来使它工作:
$ b

代码:



  atm in / home / atm / git / django_repos 
$ for`cat clone`;做`git clone $ f`;完成






您可以在 gist.github.com ,就像

 #!/ bin / rel =noreferrer> this one ,从GitHub克隆所有的回购: bash 

#Copyright 2011,Tim Branyen @tbranyen< tim@tabdeveloper.com>
#根据MIT和GPL许可证授予双重许可。

#自动将单个或多个Repos复制到一个文件夹中,
#非常适合设置git项目文件夹。

#安装:curl https://gist.github.com/raw/902154/github.sh> / usr / local / bin / gh
#chmod + x / usr / local / bin / gh


#内部属性
GITHUB_PREFIX = git @ github。 com:
GITHUB_USERNAME = $(git config --global github.user)

main main {
#未正确配置的用户
detect_user

#缺少参数
args = $ 1
if [-z $ args];然后
echo'
gh:try''``gh --help`''获取更多信息
'
退出
fi

#显示帮助文本
if [$ args ='--help'];然后
echo'
从您的GitHub克隆回购
gh repo1 repo2

从其他人克隆回购GitHub
gh用户名/ repo1用户名/ repo2

克隆混合回购:
gh回购1用户名/回购2

克隆行分隔回购文件:
cat file | xargs gh
'
exit
fi

#解析参数和克隆仓库。
find_repos


函数detect_user {
#如果没有配置用户名,尝试从git中取出--config
if [-n$ GITHUB_USERNAME ];然后
USERNAME = $ GITHUB_USERNAME
else
echo'
gh:丢失用户名
配置用户名''git config --global github.user username'''
'
退出
fi
}

函数find_repos {
用于$ args中的回购; do
#如果用户在该特定存储库中提供参数username / repo pull。
if [`awk -v repo =$ repo-v delimit =/'BEGIN {print index(repo,delimit)}'-ne 0];然后
回显拉入$回购;
git clone $ GITHUB_PREFIX $ repo.git

#默认为你。
else
echo拉入$ USERNAME / $ repo;
git clone $ GITHUB_PREFIX $ USERNAME / $ repo.git
fi
完成
}

主要$ *


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?

BR

解决方案

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 <tim@tabdeveloper.com>
# 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
GITHUB_PREFIX=git@github.com:
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 $*

这篇关于在一个本地目录签出多个git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆