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