logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

gitsubmodules.7 (13896B)


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