Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between .gitmodules and specifying submodules in .git/config?

Tags:

git

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?

like image 522
Stann Avatar asked May 04 '12 17:05

Stann


People also ask

When should I use git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

What is the point of git submodules?

Git submodules allow you to keep a git repository as a subdirectory of another git repository. Git submodules are simply a reference to another repository at a particular snapshot in time. Git submodules enable a Git repository to incorporate and track version history of external code.

What does the .gitmodules file do?

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 git-config[1]. The file contains one subsection per submodule, and the subsection value is the name of the submodule.

What is the advantage of using submodules?

The first important advantage to using submodules is that submodules allow you to keep the commit history of the component you're including in your project. Assuming the component you're adding is publicly available as a git repository, incorporating this component without the use of submodules presents a problem.


1 Answers

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

like image 73
Artefact2 Avatar answered Sep 28 '22 13:09

Artefact2