I want to add a submodule with a variable in the path so that everyone can use the same .gitmodules.
ie... git submodule add $USER/pub/repo.git
I don't want $USER to expand inside .gitmodules. I tried git submodule add '$USER/pub/repo.git'
but it cannot find the repo. I see the same behavior when trying to add a remote with an env variable.
It's impossible because git
doesn't expand environment variables in URLs.
To do what you want use git config --global url.<base>.insteadOf
to substitute URLs on the fly. Everyone in your team has to set URL replacement:
git config --global url.<new-url>.insteadOf <old-url>
See more examples in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With