windows - 将多个存储库克隆到公共(public)父文件夹结构中

标签 windows git github

我的问题是,我有一个客户,我们称他们为“邪恶公司”,它通过各种项目为我的公司提供大量业务,我们使用 GitHub 存储库来实现这些业务。我们取 2 并将它们称为“TotallyNotPolluting”和“CoveringUpPolluting”。

我希望我的员工在克隆时能够默认将“TotallyNotPolluting”存储库克隆到“EvilCorp”文件夹中。

行为:

所以起始结构是:

E:
└── Work
    └── Repos
  1. 具有起始文件夹结构:E:\Work\Repos 开始
  2. 在 Git Bash/GitHub Desktop/whatever 中克隆存储库“TotallyNotPolluting”(所选位置是起始文件夹结构 E:\Work\Repos)
  3. 结束文件夹结构:E:\Work\Repos\EvilCorp\TotallyNotPolluting
  4. 在 Git Bash/GitHub Desktop/whatever 中克隆存储库“CoveringUpPolluting”(所选位置是起始文件夹结构 E:\Work\Repos)
  5. 结束文件夹结构:E:\Work\Repos\EvilCorp\CoveringUpPolluting

所以最终的结构是:

E:
└── Work
    └── Repos
        └── EvilCorp
            ├── TotallyNotPolluting
            └── CoveringUpPolluting

这样,所有存储库都会组织到客户端文件夹中,而无需员工采取额外的步骤来执行此操作。

这可能吗?要让克隆操作创建然后克隆到(如果不存在)或克隆到(如果存在)父目录?

注意:我已经研究过使用子模块,但我不想要包含其他存储库的存储库“EvilCorp”。我只想要克隆时的文件夹。

最佳答案

您可以编写如下脚本。我还没有正确测试它,但这应该会给你移动它的正确方向。这个shell脚本的目的是创建一个父目录,然后单独创建每个子文件夹,检查子文件夹是否为空。如果为空,则克隆存储库。该 shell 脚本可以作为可执行文件分发给员工,然后在运行时将存储库克隆到正确的位置。

#create the directory, if it does not exist

directoryName="<your directory name here>"
mkdir -p directoryName
repos="TotallyNotPolluting CoveringUpPolluting"
forwardSlash="/"
#go into directory
pushd $directoryName



for repo in $repos; do

    #check if directory is not present, if true, create the directory

    [ ! -d $repo ] && mkdir -p $repo

    #go into directory

    currentDirectory=$directoryName$forwardSlash$repo
    if [ "$(ls -A $currentDirectory)" ]; then

     echo "directory is not empty, skipping to clone"
    else
        pushd $directoryName$forwardSlash$repo
        git clone "git@$codeHost:$codeUser/$repo.git"
    fi

done

关于windows - 将多个存储库克隆到公共(public)父文件夹结构中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39518432/

相关文章:

windows - 使用 Windows 机器将 Django 部署到 Heroku(生产服务器而非开发服务器)

c++ - 如何用 cvmGet 替换对 cvGetReal2D 的调用?

Git,不同的下游和上游远程分支

git 在推送时抛出破损的管道错误

python - 适用于Python版本3.9的Numpy安装

c - 暂停远程进程的执行(C、Windows)

node.js - git push heroku master 失败并出现解析错误 - 哪个文件?

git - 使用git本地跟踪项目后,如何将其添加到GitHub?

git - 如何从intellij idea做git pull请求?

git - 如何查看Github用户内容?