根据目标仓库选择git子模块

时间:2019-04-12 08:06:26

标签: git git-submodules

我有一个项目,正在使用.git/config文件中的以下内容将其推送到2个不同的存储库:

    [remote "origin"]
        url = the_main_repo
        fetch = +refs/heads/*:refs/remotes/origin/*
    [remote "other_repo"]
        url = the_other_repo

项目本身也有一个子模块。我的.gitmodules文件看起来像:

    [submodule "the_submodule"]
        path = the_submodule
        url = the_submodule_repo_url

我希望the_submodule_repo_url有所不同,具体取决于我要从哪个存储库中提取,以便从同一源(那些是我网络中的不同服务器)获取子模块存储库。

如何实现?

1 个答案:

答案 0 :(得分:0)

Git认为子模块应该有一个URL,所以没有简单的方法可以完成您想要的事情。 Git可以substitute URLs on the fly,但是在您的情况下,应该动态使用它(在命令行中,而不是在配置中)。

为子模块将一个URL设置为与其中一个遥控器相同的主机。对于其他远程运行

git -c url.$the_other_submodule_repo.insteadOf the_submodule_repo_url fetch/push/pull other_repo

创建一个shell脚本,函数或git别名以简化对其的调用。