远程 url 环境变量

Enc*_*lon 5 git git-remote

我想在路径中添加一个带有变量的子模块,以便每个人都可以使用相同的 .gitmodules。

即...git submodule add $USER/pub/repo.git我不希望 $USER 在 .gitmodules 内扩展。我尝试过git submodule add '$USER/pub/repo.git',但找不到存储库。当尝试使用环境变量添加远程时,我看到了相同的行为。

phd*_*phd 6

这是不可能的,因为git不会扩展 URL 中的环境变量。

要执行您想要的操作,请使用git config --global url.<base>.insteadOf动态替换 URL。团队中的每个人都必须设置 URL 替换:

git config --global url.<new-url>.insteadOf <old-url>
Run Code Online (Sandbox Code Playgroud)

请参阅https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof中的更多示例

  • 在我的具体示例中.. `git config --global url.$USER/pub GITPUB` 然后在存储库中。`git 子模块添加 GITPUB/repo.git` PS。你的知识令人印象深刻 (2认同)