Probably very silly question, - but I've been specifying submodules up until now in .gitmodules file. It recently struck me that perhaps it's possible to just use .git/config for the same reason so I won't have to keep extraneous file in working directory?
.git/config :
[submodule "path/to/repo"]
url = [email protected]:username/repo.git
.gitmodules
[submodule "path/to/repo"]
path = path/to/repo
url = [email protected]:username/repo.git
Are these basically the same things?
-
Not a silly question - excellent question, I'd say! :)drkvogel– drkvogel2022年05月02日 02:36:43 +00:00Commented May 2, 2022 at 2:36
2 Answers 2
Same answer than .git/info/exclude
and .gitignore
.
The .gitmodules
file can be included in the repository and shared with everyone (that is, it can be added and committed like any regular file), whereas anything in .git
(like .git/config
) is private (you cannot add it in the repository).
-
7what if I have different repos specified in .git/config and .gitmodules - which one would take precedence?Stann– Stann2012年05月04日 19:00:41 +00:00Commented May 4, 2012 at 19:00
-
I have confused, because
.git/config
contains absolute URL always, whether .gitmodules contains relative URLs.betontalpfa– betontalpfa2020年04月28日 08:04:18 +00:00Commented Apr 28, 2020 at 8:04 -
1@Stann I am a bit late. But, speaking from experience, git will use the path specified in the .git/config. Basically, git reads the .gitmodules file (when explicitly told to do so) and then saves the relevant info in the config. In the event the URL does end up changing, you will need to perform a force init or manually delete the existing submodule section from config and then perform a
submodule init
again.SNikhill– SNikhill2022年07月07日 06:21:28 +00:00Commented Jul 7, 2022 at 6:21
The git submodule sync
will update your config file with the details from the .gitmodules file, so the latter should be considered the 'master' - it's passed between repos as stated by @Artefact2.
This is useful when submodule URLs change upstream and you need to update your local repositories accordingly.
-
1which one would take precedence if they have different repos specified?Stann– Stann2012年05月04日 19:10:39 +00:00Commented May 4, 2012 at 19:10
-
4for the
sync
sub-command it is the .gitmodules that takes precedence, but see the manual for the extra conditions about those not listed in config.Philip Oakley– Philip Oakley2012年05月05日 19:25:49 +00:00Commented May 5, 2012 at 19:25