Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put a .gitmodules file in a subdirectory?

Let's say my repo index root is in /project dir. Should the .gitmodules also be inside this dir, or can I put it into, say /project/subdir?

The reason I would like to do that is because I have multiple contributors and I want each to be responsible for his own set of submodules.

like image 925
snitko Avatar asked Sep 05 '13 02:09

snitko


People also ask

How do I add a submodule to a specific folder?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

What is the use of .gitmodules file?

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.

Can submodules have submodules?

Cloning a Project with Submodules If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.

Where are submodules stored in git?

A submodule can be located anywhere in a parent Git repository's working directory and is configured via a . gitmodules file located at the root of the parent repository. This file contains which paths are submodules and what URL should be used when cloning and fetching for that submodule.


1 Answers

man gitsubmodule on Debian Wheezy says:

...
SYNOPSIS
   $GIT_WORK_DIR/.gitmodules
...

According this default place for .gitmodules file is a top-level directory of the git working tree. So, lets say you have such project structure:

project/
|
|--subproject-1/
|  `--.gitmodules
|--subproject-2/
|  `--.gitmodules
|--.gitmodules

.gitmodules in your project root dir will define modules subproject-1 and subproject-2. Subprojects dependent modules also can be defined with subproject-N/.gitmodules, but those settings will affect only in proper subproject scope.

To update your project dependencies you should use command:

git submodule update

But if you want to update also dependencies of subproject-1 and subproject-2 use:

git submoudle update --recursive
like image 78
Alexander Yancharuk Avatar answered Oct 16 '22 17:10

Alexander Yancharuk