Changing https-address of submodules in .git/config to ssh-address

前端 未结 2 1514
情深已故
情深已故 2021-01-24 05:01

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

相关标签:
2条回答
  • 2021-01-24 05:33

    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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题