2 .\" Title: gitsubmodules
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.45.2.648.g1e1586e4ed
10 .TH "GITSUBMODULES" "7" "2024\-06\-24" "Git 2\&.45\&.2\&.648\&.g1e1586" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 gitsubmodules \- Mounting one repository inside another
35 \&.gitmodules, $GIT_DIR/config
40 git <command> \-\-recurse\-submodules
45 A submodule is a repository embedded inside another repository\&. The submodule has its own history; the repository it is embedded in is called a superproject\&.
47 On the filesystem, a submodule usually (but not always \- see FORMS below) consists of (i) a Git directory located under the \fB$GIT_DIR/modules/\fR directory of its superproject, (ii) a working directory inside the superproject\(cqs working directory, and a \fB\&.git\fR file at the root of the submodule\(cqs working directory pointing to (i)\&.
49 Assuming the submodule has a Git directory at \fB$GIT_DIR/modules/foo/\fR and a working directory at \fBpath/to/bar/\fR, the superproject tracks the submodule via a \fBgitlink\fR entry in the tree at \fBpath/to/bar\fR and an entry in its \fB\&.gitmodules\fR file (see \fBgitmodules\fR(5)) of the form \fBsubmodule\&.foo\&.path = path/to/bar\fR\&.
51 The \fBgitlink\fR entry contains the object name of the commit that the superproject expects the submodule\(cqs working directory to be at\&.
53 The section \fBsubmodule\&.foo\&.*\fR in the \fB\&.gitmodules\fR file gives additional hints to Git\(cqs porcelain layer\&. For example, the \fBsubmodule\&.foo\&.url\fR setting specifies where to obtain the submodule\&.
55 Submodules can be used for at least two different use cases:
65 Using another project while maintaining independent history\&. Submodules allow you to contain the working tree of another project within your own working tree while keeping the history of both projects separate\&. Also, since submodules are fixed to an arbitrary version, the other project can be independently developed without affecting the superproject, allowing the superproject project to fix itself to new versions only when desired\&.
76 Splitting a (logically single) project into multiple repositories and tying them back together\&. This can be used to overcome current limitations of Git\(cqs implementation to have finer grained access:
86 Size of the Git repository: In its current form Git scales up poorly for large repositories containing content that is not compressed by delta computation between trees\&. For example, you can use submodules to hold large binary assets and these repositories can be shallowly cloned such that you do not have a large history locally\&.
97 Transfer size: In its current form Git requires the whole working tree present\&. It does not allow partial trees to be transferred in fetch or clone\&. If the project you work on consists of multiple repositories tied together as submodules in a superproject, you can avoid fetching the working trees of the repositories you are not interested in\&.
108 Access control: By restricting user access to submodules, this can be used to implement read/write policies for different users\&.
111 .SH "THE CONFIGURATION OF SUBMODULES"
113 Submodule operations can be configured using the following mechanisms (from highest to lowest precedence):
123 The command line for those commands that support taking submodules as part of their pathspecs\&. Most commands have a boolean flag
124 \fB\-\-recurse\-submodules\fR
125 which specifies whether to recurse into submodules\&. Examples are
128 \fBcheckout\fR\&. Some commands take enums, such as
131 \fBpush\fR, where you can specify how submodules are affected\&.
142 The configuration inside the submodule\&. This includes
143 \fB$GIT_DIR/config\fR
144 in the submodule, but also settings in the tree such as a
145 \fB\&.gitattributes\fR
148 files that specify behavior of commands inside the submodule\&.
150 For example an effect from the submodule\(cqs
152 file would be observed when you run
153 \fBgit status \-\-ignore\-submodules=none\fR
154 in the superproject\&. This collects information from the submodule\(cqs working directory by running
156 in the submodule while paying attention to the
158 file of the submodule\&.
161 \fB$GIT_DIR/config\fR
162 file would come into play when running
163 \fBgit push \-\-recurse\-submodules=check\fR
164 in the superproject, as this would check if the submodule has any changes not published to any remote\&. The remotes are configured in the submodule as usual in the
165 \fB$GIT_DIR/config\fR
177 The configuration file
178 \fB$GIT_DIR/config\fR
179 in the superproject\&. Git only recurses into active submodules (see "ACTIVE SUBMODULES" section below)\&.
181 If the submodule is not yet initialized, then the configuration inside the submodule does not exist yet, so where to obtain the submodule from is configured here for example\&.
194 file inside the superproject\&. A project usually uses this file to suggest defaults for the upstream collection of repositories for the mapping that is required between a submodule\(cqs name and its path\&.
196 This file mainly serves as the mapping between the name and path of submodules in the superproject, such that the submodule\(cqs Git directory can be located\&.
198 If the submodule has never been initialized, this is the only place where submodule configuration is found\&. It serves as the last fallback to specify where to obtain the submodule from\&.
202 Submodules can take the following forms:
212 The basic form described in DESCRIPTION with a Git directory, a working directory, a
226 "Old\-form" submodule: A working directory with an embedded
228 directory, and the tracking
232 entry in the superproject\&. This is typically found in repositories generated using older versions of Git\&.
234 It is possible to construct these old form repositories manually\&.
236 When deinitialized or deleted (see below), the submodule\(cqs Git directory is automatically moved to
237 \fB$GIT_DIR/modules/<name>/\fR
238 of the superproject\&.
249 Deinitialized submodule: A
252 entry, but no submodule working directory\&. The submodule\(cqs Git directory may be there as after deinitializing the Git directory is kept around\&. The directory which is supposed to be the working directory is empty instead\&.
254 A submodule can be deinitialized by running
255 \fBgit submodule deinit\fR\&. Besides emptying the working directory, this command only modifies the superproject\(cqs
256 \fB$GIT_DIR/config\fR
257 file, so the superproject\(cqs history is not affected\&. This can be undone using
258 \fBgit submodule init\fR\&.
269 Deleted submodule: A submodule can be deleted by running
270 \fBgit rm <submodule\-path> && git commit\fR\&. This can be undone using
273 The deletion removes the superproject\(cqs tracking data, which are both the
275 entry and the section in the
277 file\&. The submodule\(cqs working directory is removed from the file system, but the Git directory is kept around as it to make it possible to checkout past commits without requiring fetching from another repository\&.
279 To completely remove a submodule, manually delete
280 \fB$GIT_DIR/modules/<name>/\fR\&.
282 .SH "ACTIVE SUBMODULES"
284 A submodule is considered active,
295 \fBsubmodule\&.<name>\&.active\fR
310 if the submodule\(cqs path matches the pathspec in
311 \fBsubmodule\&.active\fR
325 \fBsubmodule\&.<name>\&.url\fR
329 and these are evaluated in this order\&.
339 url = https://example\&.org/foo
342 url = https://example\&.org/bar
344 url = https://example\&.org/baz
350 In the above config only the submodules \fIbar\fR and \fIbaz\fR are active, \fIbar\fR due to (1) and \fIbaz\fR due to (3)\&. \fIfoo\fR is inactive because (1) takes precedence over (3)
352 Note that (3) is a historical artefact and will be ignored if the (1) and (2) specify that the submodule is not active\&. In other words, if we have a \fBsubmodule\&.<name>\&.active\fR set to \fBfalse\fR or if the submodule\(cqs path is excluded in the pathspec in \fBsubmodule\&.active\fR, the url doesn\(cqt matter whether it is present or not\&. This is illustrated in the example that follows\&.
360 url = https://example\&.org/foo
362 url = https://example\&.org/bar
364 url = https://example\&.org/baz
369 active = :(exclude) baz
375 In here all submodules except \fIbaz\fR (foo, bar, bob) are active\&. \fIfoo\fR due to its own active flag and all the others due to the submodule active pathspec, which specifies that any submodule starting with \fIb\fR except \fIbaz\fR are also active, regardless of the presence of the \&.url field\&.
376 .SH "WORKFLOW FOR A THIRD PARTY LIBRARY"
383 git submodule add <URL> <path>
393 # Occasionally update the submodule to a new version:
394 git \-C <path> checkout <new\-version>
396 git commit \-m "update submodule to new version"
406 # See the list of submodules in a superproject
417 # See FORMS on removing submodules
422 .SH "WORKFLOW FOR AN ARTIFICIALLY SPLIT REPO"
428 # Enable recursion for relevant commands, such that
429 # regular commands recurse into submodules by default
430 git config \-\-global submodule\&.recurse true
440 # Unlike most other commands below, clone still needs
441 # its own recurse flag:
442 git clone \-\-recurse <URL> <directory>
453 # Get to know the code:
455 git ls\-files \-\-recurse\-submodules
465 .nr an-no-space-flag 1
473 \fBgit ls\-files\fR also requires its own \fB\-\-recurse\-submodules\fR flag\&.
500 .SH "IMPLEMENTATION DETAILS"
502 When cloning or pulling a repository containing submodules the submodules will not be checked out by default; you can instruct \fBclone\fR to recurse into submodules\&. The \fBinit\fR and \fBupdate\fR subcommands of \fBgit submodule\fR will maintain submodules checked out and at an appropriate revision in your working tree\&. Alternatively you can set \fBsubmodule\&.recurse\fR to have \fBcheckout\fR recurse into submodules (note that \fBsubmodule\&.recurse\fR also affects other Git commands, see \fBgit-config\fR(1) for a complete list)\&.
505 \fBgit-submodule\fR(1), \fBgitmodules\fR(5)\&.
508 Part of the \fBgit\fR(1) suite