Can I override the URL of a nested git submodule without forking?
Asked Answered
H

2

8

I have a Git repository which uses a submodule for a 3rd party library. This 3rd party library also uses submodules.

I actually found a very obscure bug in one of the 3rd party submodules which is literally a 2-line fix to get it working for my situation.

How can I keep this change around in my actual Git repository, without having to fork the 3rd party library, update the submodule URL and point that to another fork so I can commit and fix the bug? Can I override the 3rd party submodules URLs from my Git repository?

If it's not possible I'll probably end up making a pre-build event to copy my version of the file to the right location, but that feels extremely hacky... But I don't feel like having to maintain two forks for a 3rd party library that overal works just fine either.

I'm aware I could make a pull request to get the bug fixed, but lets assume the author would not be interested in having a fix that only fixes something for my particular case, which would not be unreasonable - yet, I still want this fix in my repository.

Hedron answered 6/10, 2016 at 10:54 Comment(0)
O
4

You asked

Can I override the 3rd party submodules URLs from my Git repository?

Maybe what you looked for is this:

git config submodule.SubModuleName.url PRIVATE_URL

Note

Since the URL in the .gitmodules file is what other people will first try to clone/fetch from, make sure to use a URL that they can access if possible. For example, if you use a different URL to push to than others would to pull from, use the one that others have access to. You can overwrite this value locally with git config submodule.DbConnector.url PRIVATE_URL for your own use. When applicable, a relative URL can be helpful.

from 7.11 Git Tools - Submodules

Odontalgia answered 15/1, 2018 at 18:38 Comment(2)
Thanks for pointing that out. I do wonder though if that works for submodules of a submodule. The Submodule in question is a collection of other submodules, of which I want to override one.Hedron
This works for a direct submodule, but not a nested submodule like the question asks.Coition
T
0

I just noticed that at least with git 1.34.1, for submodules of a submodule, using a git config submodule.Submodule.url ... doesn't override the URL that exists in .gitmodules.

Tortuosity answered 29/6, 2023 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.