Reputation: 5168
I need to use ssh forwarding-agent to enable git cloning on remote servers. The repository has submodules which were originally added with their https
addresses. In order for forwarding agent to work, I think I need to change those addresses to their corresponding ssh
address.
Will changing these addresses in .git/config
solve my problem?
Upvotes: 1
Views: 2604
Reputation: 3752
Recently, github deprecated usage of git://
protocol and I wanted to update the submodules in my repository to use https://
instead of git://
.
I did the following:
$ vim .gitmodules # Change all the git:// URLs into https:// URLs
$ git submodule init
$ git add .gitmodules
$ git commit -m "Update submodules"
$ git push origin main
You can do the same to convert URLs to ssh://
.
Upvotes: -1
Reputation: 12262
The URL of the module is stored in .gitmodules
at the root of your sandbox. This file is tracked as part of the Git repository. If you make the change here and commit it, it will be visible to other users of the Git repo.
When you call git submodule sync
and then git submodule init
, the URL is resolved and copied to .git/config
. When you call git submodule update
, the submodule is cloned and its URL is also found in .git/modules/<module-name>/config
.
To permanently change the URL, edit .gitmodules
and call git submodule sync
and git submodule init
again.
To temporarily change the URL, make these two changes instead:
Change the URL in .git/config
for the submodule
Go inside the submodule and call:
git remote set-url origin <new-url-with-https>
The second command will update the URL in .git/modules/<module-name>/config
which is the .git
folder for the submodule.
EDIT: If the module and submodules all live on the same server, using relative URLs for your submodules will solve the problem once and for all: each sandbox will fetch the submodules using the same protocol the main repo was cloned with. See also: https://stackoverflow.com/a/68120599/3216427
Upvotes: 5
Reputation: 94676
Use git config --global url.<base>.insteadOf
to substitute URLs on the fly. Something like
git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git
See more examples in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof
Upvotes: 4