1GIT-SUBMODULE(1)                  Git Manual                  GIT-SUBMODULE(1)
2
3
4

NAME

6       git-submodule - Initialize, update or inspect submodules
7

SYNOPSIS

9       git submodule [--quiet] [--cached]
10       git submodule [--quiet] add [<options>] [--] <repository> [<path>]
11       git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
12       git submodule [--quiet] init [--] [<path>...]
13       git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>...)
14       git submodule [--quiet] update [<options>] [--] [<path>...]
15       git submodule [--quiet] set-branch [<options>] [--] <path>
16       git submodule [--quiet] set-url [--] <path> <newurl>
17       git submodule [--quiet] summary [<options>] [--] [<path>...]
18       git submodule [--quiet] foreach [--recursive] <command>
19       git submodule [--quiet] sync [--recursive] [--] [<path>...]
20       git submodule [--quiet] absorbgitdirs [--] [<path>...]
21

DESCRIPTION

23       Inspects, updates and manages submodules.
24
25       For more information about submodules, see gitsubmodules(7).
26

COMMANDS

28       With no arguments, shows the status of existing submodules. Several
29       subcommands are available to perform operations on the submodules.
30
31       add [-b <branch>] [-f|--force] [--name <name>] [--reference
32       <repository>] [--depth <depth>] [--] <repository> [<path>]
33           Add the given repository as a submodule at the given path to the
34           changeset to be committed next to the current project: the current
35           project is termed the "superproject".
36
37           <repository> is the URL of the new submodule’s origin repository.
38           This may be either an absolute URL, or (if it begins with ./ or
39           ../), the location relative to the superproject’s default remote
40           repository (Please note that to specify a repository foo.git which
41           is located right next to a superproject bar.git, you’ll have to use
42           ../foo.git instead of ./foo.git - as one might expect when
43           following the rules for relative URLs - because the evaluation of
44           relative URLs in Git is identical to that of relative directories).
45
46           The default remote is the remote of the remote-tracking branch of
47           the current branch. If no such remote-tracking branch exists or the
48           HEAD is detached, "origin" is assumed to be the default remote. If
49           the superproject doesn’t have a default remote configured the
50           superproject is its own authoritative upstream and the current
51           working directory is used instead.
52
53           The optional argument <path> is the relative location for the
54           cloned submodule to exist in the superproject. If <path> is not
55           given, the canonical part of the source repository is used ("repo"
56           for "/path/to/repo.git" and "foo" for "host.xz:foo/.git"). If
57           <path> exists and is already a valid Git repository, then it is
58           staged for commit without cloning. The <path> is also used as the
59           submodule’s logical name in its configuration entries unless --name
60           is used to specify a logical name.
61
62           The given URL is recorded into .gitmodules for use by subsequent
63           users cloning the superproject. If the URL is given relative to the
64           superproject’s repository, the presumption is the superproject and
65           submodule repositories will be kept together in the same relative
66           location, and only the superproject’s URL needs to be provided.
67           git-submodule will correctly locate the submodule using the
68           relative URL in .gitmodules.
69
70       status [--cached] [--recursive] [--] [<path>...]
71           Show the status of the submodules. This will print the SHA-1 of the
72           currently checked out commit for each submodule, along with the
73           submodule path and the output of git describe for the SHA-1. Each
74           SHA-1 will possibly be prefixed with - if the submodule is not
75           initialized, + if the currently checked out submodule commit does
76           not match the SHA-1 found in the index of the containing repository
77           and U if the submodule has merge conflicts.
78
79           If --cached is specified, this command will instead print the SHA-1
80           recorded in the superproject for each submodule.
81
82           If --recursive is specified, this command will recurse into nested
83           submodules, and show their status as well.
84
85           If you are only interested in changes of the currently initialized
86           submodules with respect to the commit recorded in the index or the
87           HEAD, git-status(1) and git-diff(1) will provide that information
88           too (and can also report changes to a submodule’s work tree).
89
90       init [--] [<path>...]
91           Initialize the submodules recorded in the index (which were added
92           and committed elsewhere) by setting submodule.$name.url in
93           .git/config, using the same setting from .gitmodules as a template.
94           If the URL is relative, it will be resolved using the default
95           remote. If there is no default remote, the current repository will
96           be assumed to be upstream.
97
98           Optional <path> arguments limit which submodules will be
99           initialized. If no path is specified and submodule.active has been
100           configured, submodules configured to be active will be initialized,
101           otherwise all submodules are initialized.
102
103           It will also copy the value of submodule.$name.update, if present
104           in the .gitmodules file, to .git/config, but (1) this command does
105           not alter existing information in .git/config, and (2)
106           submodule.$name.update that is set to a custom command is not
107           copied for security reasons.
108
109           You can then customize the submodule clone URLs in .git/config for
110           your local setup and proceed to git submodule update; you can also
111           just use git submodule update --init without the explicit init step
112           if you do not intend to customize any submodule locations.
113
114           See the add subcommand for the definition of default remote.
115
116       deinit [-f|--force] (--all|[--] <path>...)
117           Unregister the given submodules, i.e. remove the whole
118           submodule.$name section from .git/config together with their work
119           tree. Further calls to git submodule update, git submodule foreach
120           and git submodule sync will skip any unregistered submodules until
121           they are initialized again, so use this command if you don’t want
122           to have a local checkout of the submodule in your working tree
123           anymore.
124
125           When the command is run without pathspec, it errors out, instead of
126           deinit-ing everything, to prevent mistakes.
127
128           If --force is specified, the submodule’s working tree will be
129           removed even if it contains local modifications.
130
131           If you really want to remove a submodule from the repository and
132           commit that use git-rm(1) instead. See gitsubmodules(7) for removal
133           options.
134
135       update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow]
136       [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>]
137       [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch]
138       [--filter <filter spec>] [--] [<path>...]
139           Update the registered submodules to match what the superproject
140           expects by cloning missing submodules, fetching missing commits in
141           submodules and updating the working tree of the submodules. The
142           "updating" can be done in several ways depending on command line
143           options and the value of submodule.<name>.update configuration
144           variable. The command line option takes precedence over the
145           configuration variable. If neither is given, a checkout is
146           performed. (note: what is in .gitmodules file is irrelevant at this
147           point; see git submodule init above for how .gitmodules is used).
148           The update procedures supported both from the command line as well
149           as through the submodule.<name>.update configuration are:
150
151           checkout
152               the commit recorded in the superproject will be checked out in
153               the submodule on a detached HEAD.
154
155               If --force is specified, the submodule will be checked out
156               (using git checkout --force), even if the commit specified in
157               the index of the containing repository already matches the
158               commit checked out in the submodule.
159
160           rebase
161               the current branch of the submodule will be rebased onto the
162               commit recorded in the superproject.
163
164           merge
165               the commit recorded in the superproject will be merged into the
166               current branch in the submodule.
167
168           The following update procedures have additional limitations:
169
170           custom command
171               mechanism for running arbitrary commands with the commit ID as
172               an argument. Specifically, if the submodule.<name>.update
173               configuration variable is set to !custom command, the object
174               name of the commit recorded in the superproject for the
175               submodule is appended to the custom command string and
176               executed. Note that this mechanism is not supported in the
177               .gitmodules file or on the command line.
178
179           none
180               the submodule is not updated. This update procedure is not
181               allowed on the command line.
182
183           If the submodule is not yet initialized, and you just want to use
184           the setting as stored in .gitmodules, you can automatically
185           initialize the submodule with the --init option.
186
187           If --recursive is specified, this command will recurse into the
188           registered submodules, and update any nested submodules within.
189
190           If --filter <filter spec> is specified, the given partial clone
191           filter will be applied to the submodule. See git-rev-list(1) for
192           details on filter specifications.
193
194       set-branch (-b|--branch) <branch> [--] <path>, set-branch
195       (-d|--default) [--] <path>
196           Sets the default remote tracking branch for the submodule. The
197           --branch option allows the remote branch to be specified. The
198           --default option removes the submodule.<name>.branch configuration
199           key, which causes the tracking branch to default to the remote
200           HEAD.
201
202       set-url [--] <path> <newurl>
203           Sets the URL of the specified submodule to <newurl>. Then, it will
204           automatically synchronize the submodule’s new remote URL
205           configuration.
206
207       summary [--cached|--files] [(-n|--summary-limit) <n>] [commit] [--]
208       [<path>...]
209           Show commit summary between the given commit (defaults to HEAD) and
210           working tree/index. For a submodule in question, a series of
211           commits in the submodule between the given super project commit and
212           the index or working tree (switched by --cached) are shown. If the
213           option --files is given, show the series of commits in the
214           submodule between the index of the super project and the working
215           tree of the submodule (this option doesn’t allow to use the
216           --cached option or to provide an explicit commit).
217
218           Using the --submodule=log option with git-diff(1) will provide that
219           information too.
220
221       foreach [--recursive] <command>
222           Evaluates an arbitrary shell command in each checked out submodule.
223           The command has access to the variables $name, $sm_path,
224           $displaypath, $sha1 and $toplevel: $name is the name of the
225           relevant submodule section in .gitmodules, $sm_path is the path of
226           the submodule as recorded in the immediate superproject,
227           $displaypath contains the relative path from the current working
228           directory to the submodules root directory, $sha1 is the commit as
229           recorded in the immediate superproject, and $toplevel is the
230           absolute path to the top-level of the immediate superproject. Note
231           that to avoid conflicts with $PATH on Windows, the $path variable
232           is now a deprecated synonym of $sm_path variable. Any submodules
233           defined in the superproject but not checked out are ignored by this
234           command. Unless given --quiet, foreach prints the name of each
235           submodule before evaluating the command. If --recursive is given,
236           submodules are traversed recursively (i.e. the given shell command
237           is evaluated in nested submodules as well). A non-zero return from
238           the command in any submodule causes the processing to terminate.
239           This can be overridden by adding || : to the end of the command.
240
241           As an example, the command below will show the path and currently
242           checked out commit for each submodule:
243
244               git submodule foreach 'echo $sm_path `git rev-parse HEAD`'
245
246       sync [--recursive] [--] [<path>...]
247           Synchronizes submodules' remote URL configuration setting to the
248           value specified in .gitmodules. It will only affect those
249           submodules which already have a URL entry in .git/config (that is
250           the case when they are initialized or freshly added). This is
251           useful when submodule URLs change upstream and you need to update
252           your local repositories accordingly.
253
254           git submodule sync synchronizes all submodules while git submodule
255           sync -- A synchronizes submodule "A" only.
256
257           If --recursive is specified, this command will recurse into the
258           registered submodules, and sync any nested submodules within.
259
260       absorbgitdirs
261           If a git directory of a submodule is inside the submodule, move the
262           git directory of the submodule into its superproject’s
263           $GIT_DIR/modules path and then connect the git directory and its
264           working directory by setting the core.worktree and adding a .git
265           file pointing to the git directory embedded in the superprojects
266           git directory.
267
268           A repository that was cloned independently and later added as a
269           submodule or old setups have the submodules git directory inside
270           the submodule instead of embedded into the superprojects git
271           directory.
272
273           This command is recursive by default.
274

OPTIONS

276       -q, --quiet
277           Only print error messages.
278
279       --progress
280           This option is only valid for add and update commands. Progress
281           status is reported on the standard error stream by default when it
282           is attached to a terminal, unless -q is specified. This flag forces
283           progress status even if the standard error stream is not directed
284           to a terminal.
285
286       --all
287           This option is only valid for the deinit command. Unregister all
288           submodules in the working tree.
289
290       -b <branch>, --branch <branch>
291           Branch of repository to add as submodule. The name of the branch is
292           recorded as submodule.<name>.branch in .gitmodules for update
293           --remote. A special value of .  is used to indicate that the name
294           of the branch in the submodule should be the same name as the
295           current branch in the current repository. If the option is not
296           specified, it defaults to the remote HEAD.
297
298       -f, --force
299           This option is only valid for add, deinit and update commands. When
300           running add, allow adding an otherwise ignored submodule path. When
301           running deinit the submodule working trees will be removed even if
302           they contain local changes. When running update (only effective
303           with the checkout procedure), throw away local changes in
304           submodules when switching to a different commit; and always run a
305           checkout operation in the submodule, even if the commit listed in
306           the index of the containing repository matches the commit checked
307           out in the submodule.
308
309       --cached
310           This option is only valid for status and summary commands. These
311           commands typically use the commit found in the submodule HEAD, but
312           with this option, the commit stored in the index is used instead.
313
314       --files
315           This option is only valid for the summary command. This command
316           compares the commit in the index with that in the submodule HEAD
317           when this option is used.
318
319       -n, --summary-limit
320           This option is only valid for the summary command. Limit the
321           summary size (number of commits shown in total). Giving 0 will
322           disable the summary; a negative number means unlimited (the
323           default). This limit only applies to modified submodules. The size
324           is always limited to 1 for added/deleted/typechanged submodules.
325
326       --remote
327           This option is only valid for the update command. Instead of using
328           the superproject’s recorded SHA-1 to update the submodule, use the
329           status of the submodule’s remote-tracking branch. The remote used
330           is branch’s remote (branch.<name>.remote), defaulting to origin.
331           The remote branch used defaults to the remote HEAD, but the branch
332           name may be overridden by setting the submodule.<name>.branch
333           option in either .gitmodules or .git/config (with .git/config
334           taking precedence).
335
336           This works for any of the supported update procedures (--checkout,
337           --rebase, etc.). The only change is the source of the target SHA-1.
338           For example, submodule update --remote --merge will merge upstream
339           submodule changes into the submodules, while submodule update
340           --merge will merge superproject gitlink changes into the
341           submodules.
342
343           In order to ensure a current tracking branch state, update --remote
344           fetches the submodule’s remote repository before calculating the
345           SHA-1. If you don’t want to fetch, you should use submodule update
346           --remote --no-fetch.
347
348           Use this option to integrate changes from the upstream subproject
349           with your submodule’s current HEAD. Alternatively, you can run git
350           pull from the submodule, which is equivalent except for the remote
351           branch name: update --remote uses the default upstream repository
352           and submodule.<name>.branch, while git pull uses the submodule’s
353           branch.<name>.merge. Prefer submodule.<name>.branch if you want to
354           distribute the default upstream branch with the superproject and
355           branch.<name>.merge if you want a more native feel while working in
356           the submodule itself.
357
358       -N, --no-fetch
359           This option is only valid for the update command. Don’t fetch new
360           objects from the remote site.
361
362       --checkout
363           This option is only valid for the update command. Checkout the
364           commit recorded in the superproject on a detached HEAD in the
365           submodule. This is the default behavior, the main use of this
366           option is to override submodule.$name.update when set to a value
367           other than checkout. If the key submodule.$name.update is either
368           not explicitly set or set to checkout, this option is implicit.
369
370       --merge
371           This option is only valid for the update command. Merge the commit
372           recorded in the superproject into the current branch of the
373           submodule. If this option is given, the submodule’s HEAD will not
374           be detached. If a merge failure prevents this process, you will
375           have to resolve the resulting conflicts within the submodule with
376           the usual conflict resolution tools. If the key
377           submodule.$name.update is set to merge, this option is implicit.
378
379       --rebase
380           This option is only valid for the update command. Rebase the
381           current branch onto the commit recorded in the superproject. If
382           this option is given, the submodule’s HEAD will not be detached. If
383           a merge failure prevents this process, you will have to resolve
384           these failures with git-rebase(1). If the key
385           submodule.$name.update is set to rebase, this option is implicit.
386
387       --init
388           This option is only valid for the update command. Initialize all
389           submodules for which "git submodule init" has not been called so
390           far before updating.
391
392       --name
393           This option is only valid for the add command. It sets the
394           submodule’s name to the given string instead of defaulting to its
395           path. The name must be valid as a directory name and may not end
396           with a /.
397
398       --reference <repository>
399           This option is only valid for add and update commands. These
400           commands sometimes need to clone a remote repository. In this case,
401           this option will be passed to the git-clone(1) command.
402
403           NOTE: Do not use this option unless you have read the note for git-
404           clone(1)'s --reference, --shared, and --dissociate options
405           carefully.
406
407       --dissociate
408           This option is only valid for add and update commands. These
409           commands sometimes need to clone a remote repository. In this case,
410           this option will be passed to the git-clone(1) command.
411
412           NOTE: see the NOTE for the --reference option.
413
414       --recursive
415           This option is only valid for foreach, update, status and sync
416           commands. Traverse submodules recursively. The operation is
417           performed not only in the submodules of the current repo, but also
418           in any nested submodules inside those submodules (and so on).
419
420       --depth
421           This option is valid for add and update commands. Create a shallow
422           clone with a history truncated to the specified number of
423           revisions. See git-clone(1)
424
425       --[no-]recommend-shallow
426           This option is only valid for the update command. The initial clone
427           of a submodule will use the recommended submodule.<name>.shallow as
428           provided by the .gitmodules file by default. To ignore the
429           suggestions use --no-recommend-shallow.
430
431       -j <n>, --jobs <n>
432           This option is only valid for the update command. Clone new
433           submodules in parallel with as many jobs. Defaults to the
434           submodule.fetchJobs option.
435
436       --[no-]single-branch
437           This option is only valid for the update command. Clone only one
438           branch during update: HEAD or one specified by --branch.
439
440       <path>...
441           Paths to submodule(s). When specified this will restrict the
442           command to only operate on the submodules found at the specified
443           paths. (This argument is required with add).
444

FILES

446       When initializing submodules, a .gitmodules file in the top-level
447       directory of the containing repository is used to find the url of each
448       submodule. This file should be formatted in the same way as
449       $GIT_DIR/config. The key to each submodule url is
450       "submodule.$name.url". See gitmodules(5) for details.
451

SEE ALSO

453       gitsubmodules(7), gitmodules(5).
454

GIT

456       Part of the git(1) suite
457
458
459
460Git 2.43.0                        11/20/2023                  GIT-SUBMODULE(1)
Impressum