47

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?

asked May 4, 2012 at 17:33
1
  • Not a silly question - excellent question, I'd say! :) Commented May 2, 2022 at 2:36

2 Answers 2

39

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

answered May 4, 2012 at 17:47
3
  • 7
    what if I have different repos specified in .git/config and .gitmodules - which one would take precedence? Commented May 4, 2012 at 19:00
  • I have confused, because .git/config contains absolute URL always, whether .gitmodules contains relative URLs. Commented 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. Commented Jul 7, 2022 at 6:21
22

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.

answered May 4, 2012 at 18:03
2
  • 1
    which one would take precedence if they have different repos specified? Commented May 4, 2012 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. Commented May 5, 2012 at 19:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.