1GIT-SUBMODULE(1) Git Manual GIT-SUBMODULE(1)
2
3
4
6 git-submodule - Initialize, update or inspect submodules
7
9 git submodule [--quiet] add [<options>] [--] <repository> [<path>]
10 git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
11 git submodule [--quiet] init [--] [<path>...]
12 git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>...)
13 git submodule [--quiet] update [<options>] [--] [<path>...]
14 git submodule [--quiet] summary [<options>] [--] [<path>...]
15 git submodule [--quiet] foreach [--recursive] <command>
16 git submodule [--quiet] sync [--recursive] [--] [<path>...]
17 git submodule [--quiet] absorbgitdirs [--] [<path>...]
18
19
21 Inspects, updates and manages submodules.
22
23 For more information about submodules, see gitsubmodules(7).
24
26 add [-b <branch>] [-f|--force] [--name <name>] [--reference
27 <repository>] [--depth <depth>] [--] <repository> [<path>]
28 Add the given repository as a submodule at the given path to the
29 changeset to be committed next to the current project: the current
30 project is termed the "superproject".
31
32 <repository> is the URL of the new submodule’s origin repository.
33 This may be either an absolute URL, or (if it begins with ./ or
34 ../), the location relative to the superproject’s default remote
35 repository (Please note that to specify a repository foo.git which
36 is located right next to a superproject bar.git, you’ll have to use
37 ../foo.git instead of ./foo.git - as one might expect when
38 following the rules for relative URLs - because the evaluation of
39 relative URLs in Git is identical to that of relative directories).
40
41 The default remote is the remote of the remote-tracking branch of
42 the current branch. If no such remote-tracking branch exists or the
43 HEAD is detached, "origin" is assumed to be the default remote. If
44 the superproject doesn’t have a default remote configured the
45 superproject is its own authoritative upstream and the current
46 working directory is used instead.
47
48 The optional argument <path> is the relative location for the
49 cloned submodule to exist in the superproject. If <path> is not
50 given, the canonical part of the source repository is used ("repo"
51 for "/path/to/repo.git" and "foo" for "host.xz:foo/.git"). If
52 <path> exists and is already a valid Git repository, then it is
53 staged for commit without cloning. The <path> is also used as the
54 submodule’s logical name in its configuration entries unless --name
55 is used to specify a logical name.
56
57 The given URL is recorded into .gitmodules for use by subsequent
58 users cloning the superproject. If the URL is given relative to the
59 superproject’s repository, the presumption is the superproject and
60 submodule repositories will be kept together in the same relative
61 location, and only the superproject’s URL needs to be provided.
62 git-submodule will correctly locate the submodule using the
63 relative URL in .gitmodules.
64
65 status [--cached] [--recursive] [--] [<path>...]
66 Show the status of the submodules. This will print the SHA-1 of the
67 currently checked out commit for each submodule, along with the
68 submodule path and the output of git describe for the SHA-1. Each
69 SHA-1 will possibly be prefixed with - if the submodule is not
70 initialized, + if the currently checked out submodule commit does
71 not match the SHA-1 found in the index of the containing repository
72 and U if the submodule has merge conflicts.
73
74 If --recursive is specified, this command will recurse into nested
75 submodules, and show their status as well.
76
77 If you are only interested in changes of the currently initialized
78 submodules with respect to the commit recorded in the index or the
79 HEAD, git-status(1) and git-diff(1) will provide that information
80 too (and can also report changes to a submodule’s work tree).
81
82 init [--] [<path>...]
83 Initialize the submodules recorded in the index (which were added
84 and committed elsewhere) by setting submodule.$name.url in
85 .git/config. It uses the same setting from .gitmodules as a
86 template. If the URL is relative, it will be resolved using the
87 default remote. If there is no default remote, the current
88 repository will be assumed to be upstream.
89
90 Optional <path> arguments limit which submodules will be
91 initialized. If no path is specified and submodule.active has been
92 configured, submodules configured to be active will be initialized,
93 otherwise all submodules are initialized.
94
95 When present, it will also copy the value of
96 submodule.$name.update. This command does not alter existing
97 information in .git/config. You can then customize the submodule
98 clone URLs in .git/config for your local setup and proceed to git
99 submodule update; you can also just use git submodule update --init
100 without the explicit init step if you do not intend to customize
101 any submodule locations.
102
103 See the add subcommand for the definition of default remote.
104
105 deinit [-f|--force] (--all|[--] <path>...)
106 Unregister the given submodules, i.e. remove the whole
107 submodule.$name section from .git/config together with their work
108 tree. Further calls to git submodule update, git submodule foreach
109 and git submodule sync will skip any unregistered submodules until
110 they are initialized again, so use this command if you don’t want
111 to have a local checkout of the submodule in your working tree
112 anymore.
113
114 When the command is run without pathspec, it errors out, instead of
115 deinit-ing everything, to prevent mistakes.
116
117 If --force is specified, the submodule’s working tree will be
118 removed even if it contains local modifications.
119
120 If you really want to remove a submodule from the repository and
121 commit that use git-rm(1) instead. See gitsubmodules(7) for removal
122 options.
123
124 update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow]
125 [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>]
126 [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
127 Update the registered submodules to match what the superproject
128 expects by cloning missing submodules and updating the working tree
129 of the submodules. The "updating" can be done in several ways
130 depending on command line options and the value of
131 submodule.<name>.update configuration variable. The command line
132 option takes precedence over the configuration variable. If neither
133 is given, a checkout is performed. The update procedures supported
134 both from the command line as well as through the
135 submodule.<name>.update configuration are:
136
137 checkout
138 the commit recorded in the superproject will be checked out in
139 the submodule on a detached HEAD.
140
141 If --force is specified, the submodule will be checked out
142 (using git checkout --force), even if the commit specified in
143 the index of the containing repository already matches the
144 commit checked out in the submodule.
145
146 rebase
147 the current branch of the submodule will be rebased onto the
148 commit recorded in the superproject.
149
150 merge
151 the commit recorded in the superproject will be merged into the
152 current branch in the submodule.
153
154 The following update procedures are only available via the
155 submodule.<name>.update configuration variable:
156
157 custom command
158 arbitrary shell command that takes a single argument (the sha1
159 of the commit recorded in the superproject) is executed. When
160 submodule.<name>.update is set to !command, the remainder after
161 the exclamation mark is the custom command.
162
163 none
164 the submodule is not updated.
165
166 If the submodule is not yet initialized, and you just want to use
167 the setting as stored in .gitmodules, you can automatically
168 initialize the submodule with the --init option.
169
170 If --recursive is specified, this command will recurse into the
171 registered submodules, and update any nested submodules within.
172
173 summary [--cached|--files] [(-n|--summary-limit) <n>] [commit] [--]
174 [<path>...]
175 Show commit summary between the given commit (defaults to HEAD) and
176 working tree/index. For a submodule in question, a series of
177 commits in the submodule between the given super project commit and
178 the index or working tree (switched by --cached) are shown. If the
179 option --files is given, show the series of commits in the
180 submodule between the index of the super project and the working
181 tree of the submodule (this option doesn’t allow to use the
182 --cached option or to provide an explicit commit).
183
184 Using the --submodule=log option with git-diff(1) will provide that
185 information too.
186
187 foreach [--recursive] <command>
188 Evaluates an arbitrary shell command in each checked out submodule.
189 The command has access to the variables $name, $sm_path,
190 $displaypath, $sha1 and $toplevel: $name is the name of the
191 relevant submodule section in .gitmodules, $sm_path is the path of
192 the submodule as recorded in the immediate superproject,
193 $displaypath contains the relative path from the current working
194 directory to the submodules root directory, $sha1 is the commit as
195 recorded in the immediate superproject, and $toplevel is the
196 absolute path to the top-level of the immediate superproject. Note
197 that to avoid conflicts with $PATH on Windows, the $path variable
198 is now a deprecated synonym of $sm_path variable. Any submodules
199 defined in the superproject but not checked out are ignored by this
200 command. Unless given --quiet, foreach prints the name of each
201 submodule before evaluating the command. If --recursive is given,
202 submodules are traversed recursively (i.e. the given shell command
203 is evaluated in nested submodules as well). A non-zero return from
204 the command in any submodule causes the processing to terminate.
205 This can be overridden by adding || : to the end of the command.
206
207 As an example, the command below will show the path and currently
208 checked out commit for each submodule:
209
210 git submodule foreach 'echo $path `git rev-parse HEAD`'
211
212
213 sync [--recursive] [--] [<path>...]
214 Synchronizes submodules' remote URL configuration setting to the
215 value specified in .gitmodules. It will only affect those
216 submodules which already have a URL entry in .git/config (that is
217 the case when they are initialized or freshly added). This is
218 useful when submodule URLs change upstream and you need to update
219 your local repositories accordingly.
220
221 git submodule sync synchronizes all submodules while git submodule
222 sync -- A synchronizes submodule "A" only.
223
224 If --recursive is specified, this command will recurse into the
225 registered submodules, and sync any nested submodules within.
226
227 absorbgitdirs
228 If a git directory of a submodule is inside the submodule, move the
229 git directory of the submodule into its superprojects
230 $GIT_DIR/modules path and then connect the git directory and its
231 working directory by setting the core.worktree and adding a .git
232 file pointing to the git directory embedded in the superprojects
233 git directory.
234
235 A repository that was cloned independently and later added as a
236 submodule or old setups have the submodules git directory inside
237 the submodule instead of embedded into the superprojects git
238 directory.
239
240 This command is recursive by default.
241
243 -q, --quiet
244 Only print error messages.
245
246 --progress
247 This option is only valid for add and update commands. Progress
248 status is reported on the standard error stream by default when it
249 is attached to a terminal, unless -q is specified. This flag forces
250 progress status even if the standard error stream is not directed
251 to a terminal.
252
253 --all
254 This option is only valid for the deinit command. Unregister all
255 submodules in the working tree.
256
257 -b, --branch
258 Branch of repository to add as submodule. The name of the branch is
259 recorded as submodule.<name>.branch in .gitmodules for update
260 --remote. A special value of . is used to indicate that the name
261 of the branch in the submodule should be the same name as the
262 current branch in the current repository.
263
264 -f, --force
265 This option is only valid for add, deinit and update commands. When
266 running add, allow adding an otherwise ignored submodule path. When
267 running deinit the submodule working trees will be removed even if
268 they contain local changes. When running update (only effective
269 with the checkout procedure), throw away local changes in
270 submodules when switching to a different commit; and always run a
271 checkout operation in the submodule, even if the commit listed in
272 the index of the containing repository matches the commit checked
273 out in the submodule.
274
275 --cached
276 This option is only valid for status and summary commands. These
277 commands typically use the commit found in the submodule HEAD, but
278 with this option, the commit stored in the index is used instead.
279
280 --files
281 This option is only valid for the summary command. This command
282 compares the commit in the index with that in the submodule HEAD
283 when this option is used.
284
285 -n, --summary-limit
286 This option is only valid for the summary command. Limit the
287 summary size (number of commits shown in total). Giving 0 will
288 disable the summary; a negative number means unlimited (the
289 default). This limit only applies to modified submodules. The size
290 is always limited to 1 for added/deleted/typechanged submodules.
291
292 --remote
293 This option is only valid for the update command. Instead of using
294 the superproject’s recorded SHA-1 to update the submodule, use the
295 status of the submodule’s remote-tracking branch. The remote used
296 is branch’s remote (branch.<name>.remote), defaulting to origin.
297 The remote branch used defaults to master, but the branch name may
298 be overridden by setting the submodule.<name>.branch option in
299 either .gitmodules or .git/config (with .git/config taking
300 precedence).
301
302 This works for any of the supported update procedures (--checkout,
303 --rebase, etc.). The only change is the source of the target SHA-1.
304 For example, submodule update --remote --merge will merge upstream
305 submodule changes into the submodules, while submodule update
306 --merge will merge superproject gitlink changes into the
307 submodules.
308
309 In order to ensure a current tracking branch state, update --remote
310 fetches the submodule’s remote repository before calculating the
311 SHA-1. If you don’t want to fetch, you should use submodule update
312 --remote --no-fetch.
313
314 Use this option to integrate changes from the upstream subproject
315 with your submodule’s current HEAD. Alternatively, you can run git
316 pull from the submodule, which is equivalent except for the remote
317 branch name: update --remote uses the default upstream repository
318 and submodule.<name>.branch, while git pull uses the submodule’s
319 branch.<name>.merge. Prefer submodule.<name>.branch if you want to
320 distribute the default upstream branch with the superproject and
321 branch.<name>.merge if you want a more native feel while working in
322 the submodule itself.
323
324 -N, --no-fetch
325 This option is only valid for the update command. Don’t fetch new
326 objects from the remote site.
327
328 --checkout
329 This option is only valid for the update command. Checkout the
330 commit recorded in the superproject on a detached HEAD in the
331 submodule. This is the default behavior, the main use of this
332 option is to override submodule.$name.update when set to a value
333 other than checkout. If the key submodule.$name.update is either
334 not explicitly set or set to checkout, this option is implicit.
335
336 --merge
337 This option is only valid for the update command. Merge the commit
338 recorded in the superproject into the current branch of the
339 submodule. If this option is given, the submodule’s HEAD will not
340 be detached. If a merge failure prevents this process, you will
341 have to resolve the resulting conflicts within the submodule with
342 the usual conflict resolution tools. If the key
343 submodule.$name.update is set to merge, this option is implicit.
344
345 --rebase
346 This option is only valid for the update command. Rebase the
347 current branch onto the commit recorded in the superproject. If
348 this option is given, the submodule’s HEAD will not be detached. If
349 a merge failure prevents this process, you will have to resolve
350 these failures with git-rebase(1). If the key
351 submodule.$name.update is set to rebase, this option is implicit.
352
353 --init
354 This option is only valid for the update command. Initialize all
355 submodules for which "git submodule init" has not been called so
356 far before updating.
357
358 --name
359 This option is only valid for the add command. It sets the
360 submodule’s name to the given string instead of defaulting to its
361 path. The name must be valid as a directory name and may not end
362 with a /.
363
364 --reference <repository>
365 This option is only valid for add and update commands. These
366 commands sometimes need to clone a remote repository. In this case,
367 this option will be passed to the git-clone(1) command.
368
369 NOTE: Do not use this option unless you have read the note for git-
370 clone(1)'s --reference, --shared, and --dissociate options
371 carefully.
372
373 --dissociate
374 This option is only valid for add and update commands. These
375 commands sometimes need to clone a remote repository. In this case,
376 this option will be passed to the git-clone(1) command.
377
378 NOTE: see the NOTE for the --reference option.
379
380 --recursive
381 This option is only valid for foreach, update, status and sync
382 commands. Traverse submodules recursively. The operation is
383 performed not only in the submodules of the current repo, but also
384 in any nested submodules inside those submodules (and so on).
385
386 --depth
387 This option is valid for add and update commands. Create a shallow
388 clone with a history truncated to the specified number of
389 revisions. See git-clone(1)
390
391 --[no-]recommend-shallow
392 This option is only valid for the update command. The initial clone
393 of a submodule will use the recommended submodule.<name>.shallow as
394 provided by the .gitmodules file by default. To ignore the
395 suggestions use --no-recommend-shallow.
396
397 -j <n>, --jobs <n>
398 This option is only valid for the update command. Clone new
399 submodules in parallel with as many jobs. Defaults to the
400 submodule.fetchJobs option.
401
402 <path>...
403 Paths to submodule(s). When specified this will restrict the
404 command to only operate on the submodules found at the specified
405 paths. (This argument is required with add).
406
408 When initializing submodules, a .gitmodules file in the top-level
409 directory of the containing repository is used to find the url of each
410 submodule. This file should be formatted in the same way as
411 $GIT_DIR/config. The key to each submodule url is
412 "submodule.$name.url". See gitmodules(5) for details.
413
415 gitsubmodules(7), gitmodules(5).
416
418 Part of the git(1) suite
419
420
421
422Git 2.20.1 12/15/2018 GIT-SUBMODULE(1)