Git Submodules: Is it possible to have more than one URL for each?
Asked Answered
A

3

7

I was wondering if it is possible to have more than one URL for each git submodule. It would be interested to have more than one source of it if one of them is down or someone is behind a proxy that blocks one of them.

Have you ever had this problem? How would you solve it?

Aksum answered 6/1, 2010 at 19:5 Comment(0)
T
7

As far as I know, one submodule has only one url, which is referenced in:

  • .gitmodules
     $ cat .gitmodules
     [submodule "a"]
             path = a
             url = /home/moses/subtut/public/a/.git
     [submodule "b"]
             path = b
             url = /home/moses/subtut/public/b/.git
  • and in the config of the .git directory of the submodule

Meaning if that url is down, it may have to be changed in those two locations, but I have not tested that process.


Good comments from Gattster

git submodule sync. 

According to the docs:

Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules.
This is useful when submodule URLs change upstream and you need to update your local repositories accordingly.

  • "git submodule sync" synchronizes all submodules
  • while "git submodule sync -- A" synchronizes submodule "A" only.

That being said, modifying .gitmodule might be better done in isolation (i.e. in a branch) until those new url can be validated/published.

Tebet answered 6/1, 2010 at 19:12 Comment(3)
The problem of changing the URL is that when I the main repository, .gitmodules will also be commited and those URLs may not work for everyone that clones the main repository. I thought about working a local branch that the only difference from master is that its .gitmodules have different URLs. Ugly, but would work, :-/Aksum
I think you can run git submodule sync. According to the docs, it does this "Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules. This is useful when submodule URLs change upstream and you need to update your local repositories accordingly."Iaria
@qris that reminds me of #12078865 : the git submodule update is dangerous as well.Tebet
I
1

I don't believe it is possible. It should be possible to manually do this by checking out your project, initializing your submodules, and then cd into a submodule directory and update the git remote origin to the new repository URL.

Iaria answered 6/1, 2010 at 19:12 Comment(0)
S
0

From the submodule directory, use these commands to add additional remotes. If you omit the first command, it will replace your original remote URL, so you need to run both.

git remote set-url --add --push [remote] [original repo URL]
git remote set-url --add --push [remote] [second repo URL]
Sigismondo answered 20/6, 2023 at 23:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.