With Git 2.25 (Q1 2020), you can modify it.
See "Git submodule url changed" and the new command
git submodule set-url [--] <path> <newurl>
(On the --
separator, see "double hyphen as a signal to stop option interpretation and treat all following arguments literally")
WARNING: Hi-Angel mentions in the comments (tested even with Git 2.31.1):
One should be careful with git submodule set-url
because it has a bug:
If, inside your .gitmodules
file, the path looks like this some-path
, and then you execute a:
# Usually causes unexpected behavior
git submodule set-url some-path/ new-url
(note the trailing slash /
in some-path/
), then, instead of modifying existing submodule, the command will add another one. Instead run:
# Good
git submodule set-url some-path new-url
Original answer (May 2009, fourteen years ago)
Actually, a patch has been submitted in April 2009 to clarify gitmodule
role.
So now the gitmodule documentation does not yet include:
The .gitmodules
file, located in the top-level directory of a git working tree, is a text file with a syntax matching the requirements -of linkgit:git-config4.
[NEW]:
As this file is managed by Git, it tracks the +records of a project's submodules.
Information stored in this file is used as a hint to prime the authoritative version of the record stored in the project configuration file.
User specific record changes (e.g. to account for differences in submodule URLs due to networking situations) should be made to the configuration file, while record changes to be propagated (e.g. +due to a relocation of the submodule source) should be made to this file.
That pretty much confirm Jim's answer.
If you follow this git submodule tutorial, you see you need a "git submodule init
" to add the submodule repository URLs to .git/config.
"git submodule sync
" has been added in August 2008 precisely to make that task easier when URL changes (especially if the number of submodules is important).
The associate script with that command is straightforward enough:
module_list "$@" |
while read mode sha1 stage path
do
name=$(module_name "$path")
url=$(git config -f .gitmodules --get submodule."$name".url)
if test -e "$path"/.git
then
(
unset GIT_DIR
cd "$path"
remote=$(get_default_remote)
say "Synchronizing submodule url for '$name'"
git config remote."$remote".url "$url"
)
fi
done
The goal remains: git config remote."$remote".url "$url"
Note:
Git 2.40 (Q1 2023) clarifies git config remote.<remote>.url
:
See commit d390e08 (07 Feb 2023) by Calvin Wan (CalvinWan0101
).
(Merged by Junio C Hamano -- gitster
-- in commit 59397e9, 15 Feb 2023)
Documentation
: clarify multiple pushurls
vs urls
Signed-off-by: Calvin Wan
In a remote with multiple configured URLs, git remote -v
(man) shows the correct url that fetch uses.
However, git config remote.<remote>.url
(man) returns the last defined url instead.
This discrepancy can cause confusion for users with a remote defined as such, since any url defined after the first essentially acts as a pushurl
.
Add documentation to clarify how fetch interacts with multiple urls and how push interacts with multiple pushurls and urls.
urls-remotes
now includes in its man page:
The <pushurl>
is used for pushes only.
It is optional and defaults
to <URL>
.
Pushing to a remote affects all defined pushurls or to all
defined urls if no pushurls are defined.
Fetch, however, will only
fetch from the first defined url if muliple urls are defined.
Git 2.44 (Q1 2024), batch 10, tightens URL checks fsck makes in a URL recorded for submodules.
So when you change the URL, the URL validity check is now more robust.
See commit 8430b43, commit 7e2fc39, commit 6af2c4a, commit 13320ff (18 Jan 2024) by Victoria Dye (vdye
).
(Merged by Junio C Hamano -- gitster
-- in commit 76bd129, 26 Jan 2024)
Signed-off-by: Victoria Dye
Update the validation of "curl URL" submodule URLs (i.e.
those that specify an "http[s]" or "ftp[s]" protocol) in 'check_submodule_url()
' to catch more invalid URLs.
The existing validation using 'credential_from_url_gently()
' parses certain URLs incorrectly, leading to invalid submodule URLs passing 'git fsck
'(man) checks.
Conversely, 'url_normalize()
' - used to validate remote URLs in 'remote_get()
' - correctly identifies the invalid URLs missed by 'credential_from_url_gently()
'.
To catch more invalid cases, replace 'credential_from_url_gently()
' with 'url_normalize()
' followed by a 'url_decode()
' and a check for newlines (mirroring 'check_url_component()
' in the 'credential_from_url_gently()
' validation).
git submodule set-url [--] <path> <newurl>
– Skillet