summaryrefslogtreecommitdiffstats
path: root/man7/gitsubmodules.7
blob: 4223e42895b88ef1317edab0454b9571a34157ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
'\" t
.\"     Title: gitsubmodules
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2024-04-29
.\"    Manual: Git Manual
.\"    Source: Git 2.45.0
.\"  Language: English
.\"
.TH "GITSUBMODULES" "7" "2024\-04\-29" "Git 2\&.45\&.0" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
gitsubmodules \- Mounting one repository inside another
.SH "SYNOPSIS"
.sp
.nf
\&.gitmodules, $GIT_DIR/config
.fi
.sp
.nf
git submodule
git <command> \-\-recurse\-submodules
.fi
.sp
.SH "DESCRIPTION"
.sp
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\&.
.sp
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)\&.
.sp
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\&.
.sp
The \fBgitlink\fR entry contains the object name of the commit that the superproject expects the submodule\(cqs working directory to be at\&.
.sp
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\&.
.sp
Submodules can be used for at least two different use cases:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
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:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Access control: By restricting user access to submodules, this can be used to implement read/write policies for different users\&.
.RE
.RE
.SH "THE CONFIGURATION OF SUBMODULES"
.sp
Submodule operations can be configured using the following mechanisms (from highest to lowest precedence):
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The command line for those commands that support taking submodules as part of their pathspecs\&. Most commands have a boolean flag
\fB\-\-recurse\-submodules\fR
which specifies whether to recurse into submodules\&. Examples are
\fBgrep\fR
and
\fBcheckout\fR\&. Some commands take enums, such as
\fBfetch\fR
and
\fBpush\fR, where you can specify how submodules are affected\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The configuration inside the submodule\&. This includes
\fB$GIT_DIR/config\fR
in the submodule, but also settings in the tree such as a
\fB\&.gitattributes\fR
or
\fB\&.gitignore\fR
files that specify behavior of commands inside the submodule\&.
.sp
For example an effect from the submodule\(cqs
\fB\&.gitignore\fR
file would be observed when you run
\fBgit status \-\-ignore\-submodules=none\fR
in the superproject\&. This collects information from the submodule\(cqs working directory by running
\fBstatus\fR
in the submodule while paying attention to the
\fB\&.gitignore\fR
file of the submodule\&.
.sp
The submodule\(cqs
\fB$GIT_DIR/config\fR
file would come into play when running
\fBgit push \-\-recurse\-submodules=check\fR
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
\fB$GIT_DIR/config\fR
file\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The configuration file
\fB$GIT_DIR/config\fR
in the superproject\&. Git only recurses into active submodules (see "ACTIVE SUBMODULES" section below)\&.
.sp
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The
\fB\&.gitmodules\fR
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\&.
.sp
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\&.
.sp
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\&.
.RE
.SH "FORMS"
.sp
Submodules can take the following forms:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The basic form described in DESCRIPTION with a Git directory, a working directory, a
\fBgitlink\fR, and a
\fB\&.gitmodules\fR
entry\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
"Old\-form" submodule: A working directory with an embedded
\fB\&.git\fR
directory, and the tracking
\fBgitlink\fR
and
\fB\&.gitmodules\fR
entry in the superproject\&. This is typically found in repositories generated using older versions of Git\&.
.sp
It is possible to construct these old form repositories manually\&.
.sp
When deinitialized or deleted (see below), the submodule\(cqs Git directory is automatically moved to
\fB$GIT_DIR/modules/<name>/\fR
of the superproject\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Deinitialized submodule: A
\fBgitlink\fR, and a
\fB\&.gitmodules\fR
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\&.
.sp
A submodule can be deinitialized by running
\fBgit submodule deinit\fR\&. Besides emptying the working directory, this command only modifies the superproject\(cqs
\fB$GIT_DIR/config\fR
file, so the superproject\(cqs history is not affected\&. This can be undone using
\fBgit submodule init\fR\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Deleted submodule: A submodule can be deleted by running
\fBgit rm <submodule\-path> && git commit\fR\&. This can be undone using
\fBgit revert\fR\&.
.sp
The deletion removes the superproject\(cqs tracking data, which are both the
\fBgitlink\fR
entry and the section in the
\fB\&.gitmodules\fR
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\&.
.sp
To completely remove a submodule, manually delete
\fB$GIT_DIR/modules/<name>/\fR\&.
.RE
.SH "ACTIVE SUBMODULES"
.sp
A submodule is considered active,
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
if
\fBsubmodule\&.<name>\&.active\fR
is set to
\fBtrue\fR
.sp
or
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
if the submodule\(cqs path matches the pathspec in
\fBsubmodule\&.active\fR
.sp
or
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  3." 4.2
.\}
if
\fBsubmodule\&.<name>\&.url\fR
is set\&.
.RE
.sp
and these are evaluated in this order\&.
.sp
For example:
.sp
.if n \{\
.RS 4
.\}
.nf
[submodule "foo"]
  active = false
  url = https://example\&.org/foo
[submodule "bar"]
  active = true
  url = https://example\&.org/bar
[submodule "baz"]
  url = https://example\&.org/baz
.fi
.if n \{\
.RE
.\}
.sp
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)
.sp
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\&.
.sp
.if n \{\
.RS 4
.\}
.nf
[submodule "foo"]
  active = true
  url = https://example\&.org/foo
[submodule "bar"]
  url = https://example\&.org/bar
[submodule "baz"]
  url = https://example\&.org/baz
[submodule "bob"]
  ignore = true
[submodule]
  active = b*
  active = :(exclude) baz
.fi
.if n \{\
.RE
.\}
.sp
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\&.
.SH "WORKFLOW FOR A THIRD PARTY LIBRARY"
.sp
.if n \{\
.RS 4
.\}
.nf
# Add a submodule
git submodule add <URL> <path>
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# Occasionally update the submodule to a new version:
git \-C <path> checkout <new\-version>
git add <path>
git commit \-m "update submodule to new version"
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# See the list of submodules in a superproject
git submodule status
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# See FORMS on removing submodules
.fi
.if n \{\
.RE
.\}
.SH "WORKFLOW FOR AN ARTIFICIALLY SPLIT REPO"
.sp
.if n \{\
.RS 4
.\}
.nf
# Enable recursion for relevant commands, such that
# regular commands recurse into submodules by default
git config \-\-global submodule\&.recurse true
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# Unlike most other commands below, clone still needs
# its own recurse flag:
git clone \-\-recurse <URL> <directory>
cd <directory>
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# Get to know the code:
git grep foo
git ls\-files \-\-recurse\-submodules
.fi
.if n \{\
.RE
.\}
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBNote\fR
.ps -1
.br
.sp
\fBgit ls\-files\fR also requires its own \fB\-\-recurse\-submodules\fR flag\&.
.sp .5v
.RE
.sp
.if n \{\
.RS 4
.\}
.nf
# Get new code
git fetch
git pull \-\-rebase
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
# Change worktree
git checkout
git reset
.fi
.if n \{\
.RE
.\}
.SH "IMPLEMENTATION DETAILS"
.sp
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)\&.
.SH "SEE ALSO"
.sp
\fBgit-submodule\fR(1), \fBgitmodules\fR(5)\&.
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite