32

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 = git@github.com:username/repo.git

.gitmodules

[submodule "path/to/repo"]
    path = path/to/repo
    url = git@github.com:username/repo.git

Are these basically the same things?

Stann
  • 12,029
  • 18
  • 60
  • 72

2 Answers2

33

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).

Artefact2
  • 6,918
  • 3
  • 28
  • 38
  • 6
    what if I have different repos specified in .git/config and .gitmodules - which one would take precedence? – Stann May 04 '12 at 19:00
  • I have confused, because `.git/config` contains absolute URL always, whether .gitmodules contains relative URLs. – betontalpfa Apr 28 '20 at 08:04
17

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.

Philip Oakley
  • 11,745
  • 8
  • 42
  • 63
  • 1
    which one would take precedence if they have different repos specified? – Stann May 04 '12 at 19:10
  • 4
    for 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 May 05 '12 at 19:25