{
    "content": [
        {
            "type": "text",
            "text": "# gitsubmodules (man)\n\n## NAME\n\ngitsubmodules - Mounting one repository inside another\n\n## SYNOPSIS\n\n.gitmodules, $GITDIR/config\ngit submodule\ngit <command> --recurse-submodules\n\n## DESCRIPTION\n\nA submodule is a repository embedded inside another repository. The submodule has its own\nhistory; the repository it is embedded in is called a superproject.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **THE CONFIGURATION OF SUBMODULES**\n- **FORMS**\n- **ACTIVE SUBMODULES**\n- **WORKFLOW FOR A THIRD PARTY LIBRARY**\n- **WORKFLOW FOR AN ARTIFICIALLY SPLIT REPO**\n- **IMPLEMENTATION DETAILS**\n- **SEE ALSO**\n- **GIT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "gitsubmodules",
        "section": "",
        "mode": "man",
        "summary": "gitsubmodules - Mounting one repository inside another",
        "synopsis": ".gitmodules, $GITDIR/config\ngit submodule\ngit <command> --recurse-submodules",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "git-submodule",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-submodule/1/json"
            },
            {
                "name": "gitmodules",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/gitmodules/5/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 47,
                "subsections": []
            },
            {
                "name": "THE CONFIGURATION OF SUBMODULES",
                "lines": 39,
                "subsections": []
            },
            {
                "name": "FORMS",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "ACTIVE SUBMODULES",
                "lines": 50,
                "subsections": []
            },
            {
                "name": "WORKFLOW FOR A THIRD PARTY LIBRARY",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "WORKFLOW FOR AN ARTIFICIALLY SPLIT REPO",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "IMPLEMENTATION DETAILS",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "gitsubmodules - Mounting one repository inside another\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": ".gitmodules, $GITDIR/config\n\ngit submodule\ngit <command> --recurse-submodules\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "A submodule is a repository embedded inside another repository. The submodule has its own\nhistory; the repository it is embedded in is called a superproject.\n\nOn the filesystem, a submodule usually (but not always - see FORMS below) consists of (i) a\nGit directory located under the $GITDIR/modules/ directory of its superproject, (ii) a\nworking directory inside the superproject’s working directory, and a .git file at the root of\nthe submodule’s working directory pointing to (i).\n\nAssuming the submodule has a Git directory at $GITDIR/modules/foo/ and a working directory\nat path/to/bar/, the superproject tracks the submodule via a gitlink entry in the tree at\npath/to/bar and an entry in its .gitmodules file (see gitmodules(5)) of the form\nsubmodule.foo.path = path/to/bar.\n\nThe gitlink entry contains the object name of the commit that the superproject expects the\nsubmodule’s working directory to be at.\n\nThe section submodule.foo.* in the .gitmodules file gives additional hints to Git’s porcelain\nlayer. For example, the submodule.foo.url setting specifies where to obtain the submodule.\n\nSubmodules can be used for at least two different use cases:\n\n1. Using another project while maintaining independent history. Submodules allow you to\ncontain the working tree of another project within your own working tree while keeping\nthe history of both projects separate. Also, since submodules are fixed to an arbitrary\nversion, the other project can be independently developed without affecting the\nsuperproject, allowing the superproject project to fix itself to new versions only when\ndesired.\n\n2. Splitting a (logically single) project into multiple repositories and tying them back\ntogether. This can be used to overcome current limitations of Git’s implementation to\nhave finer grained access:\n\n•   Size of the Git repository: In its current form Git scales up poorly for large\nrepositories containing content that is not compressed by delta computation between\ntrees. For example, you can use submodules to hold large binary assets and these\nrepositories can be shallowly cloned such that you do not have a large history\nlocally.\n\n•   Transfer size: In its current form Git requires the whole working tree present. It\ndoes not allow partial trees to be transferred in fetch or clone. If the project you\nwork on consists of multiple repositories tied together as submodules in a\nsuperproject, you can avoid fetching the working trees of the repositories you are\nnot interested in.\n\n•   Access control: By restricting user access to submodules, this can be used to\nimplement read/write policies for different users.\n",
                "subsections": []
            },
            "THE CONFIGURATION OF SUBMODULES": {
                "content": "Submodule operations can be configured using the following mechanisms (from highest to lowest\nprecedence):\n\n•   The command line for those commands that support taking submodules as part of their\npathspecs. Most commands have a boolean flag --recurse-submodules which specify whether\nto recurse into submodules. Examples are grep and checkout. Some commands take enums,\nsuch as fetch and push, where you can specify how submodules are affected.\n\n•   The configuration inside the submodule. This includes $GITDIR/config in the submodule,\nbut also settings in the tree such as a .gitattributes or .gitignore files that specify\nbehavior of commands inside the submodule.\n\nFor example an effect from the submodule’s .gitignore file would be observed when you run\ngit status --ignore-submodules=none in the superproject. This collects information from\nthe submodule’s working directory by running status in the submodule while paying\nattention to the .gitignore file of the submodule.\n\nThe submodule’s $GITDIR/config file would come into play when running git push\n--recurse-submodules=check in the superproject, as this would check if the submodule has\nany changes not published to any remote. The remotes are configured in the submodule as\nusual in the $GITDIR/config file.\n\n•   The configuration file $GITDIR/config in the superproject. Git only recurses into active\nsubmodules (see \"ACTIVE SUBMODULES\" section below).\n\nIf the submodule is not yet initialized, then the configuration inside the submodule does\nnot exist yet, so where to obtain the submodule from is configured here for example.\n\n•   The .gitmodules file inside the superproject. A project usually uses this file to suggest\ndefaults for the upstream collection of repositories for the mapping that is required\nbetween a submodule’s name and its path.\n\nThis file mainly serves as the mapping between the name and path of submodules in the\nsuperproject, such that the submodule’s Git directory can be located.\n\nIf the submodule has never been initialized, this is the only place where submodule\nconfiguration is found. It serves as the last fallback to specify where to obtain the\nsubmodule from.\n",
                "subsections": []
            },
            "FORMS": {
                "content": "Submodules can take the following forms:\n\n•   The basic form described in DESCRIPTION with a Git directory, a working directory, a\ngitlink, and a .gitmodules entry.\n\n•   \"Old-form\" submodule: A working directory with an embedded .git directory, and the\ntracking gitlink and .gitmodules entry in the superproject. This is typically found in\nrepositories generated using older versions of Git.\n\nIt is possible to construct these old form repositories manually.\n\nWhen deinitialized or deleted (see below), the submodule’s Git directory is automatically\nmoved to $GITDIR/modules/<name>/ of the superproject.\n\n•   Deinitialized submodule: A gitlink, and a .gitmodules entry, but no submodule working\ndirectory. The submodule’s Git directory may be there as after deinitializing the Git\ndirectory is kept around. The directory which is supposed to be the working directory is\nempty instead.\n\nA submodule can be deinitialized by running git submodule deinit. Besides emptying the\nworking directory, this command only modifies the superproject’s $GITDIR/config file, so\nthe superproject’s history is not affected. This can be undone using git submodule init.\n\n•   Deleted submodule: A submodule can be deleted by running git rm <submodule path> && git\ncommit. This can be undone using git revert.\n\nThe deletion removes the superproject’s tracking data, which are both the gitlink entry\nand the section in the .gitmodules file. The submodule’s working directory is removed\nfrom the file system, but the Git directory is kept around as it to make it possible to\ncheckout past commits without requiring fetching from another repository.\n\nTo completely remove a submodule, manually delete $GITDIR/modules/<name>/.\n",
                "subsections": []
            },
            "ACTIVE SUBMODULES": {
                "content": "A submodule is considered active,\n\n1. if submodule.<name>.active is set to true\n\nor\n\n2. if the submodule’s path matches the pathspec in submodule.active\n\nor\n\n3. if submodule.<name>.url is set.\n\nand these are evaluated in this order.\n\nFor example:\n\n[submodule \"foo\"]\nactive = false\nurl = https://example.org/foo\n[submodule \"bar\"]\nactive = true\nurl = https://example.org/bar\n[submodule \"baz\"]\nurl = https://example.org/baz\n\nIn the above config only the submodule bar and baz are active, bar due to (1) and baz due to\n(3). foo is inactive because (1) takes precedence over (3)\n\nNote that (3) is a historical artefact and will be ignored if the (1) and (2) specify that\nthe submodule is not active. In other words, if we have a submodule.<name>.active set to\nfalse or if the submodule’s path is excluded in the pathspec in submodule.active, the url\ndoesn’t matter whether it is present or not. This is illustrated in the example that follows.\n\n[submodule \"foo\"]\nactive = true\nurl = https://example.org/foo\n[submodule \"bar\"]\nurl = https://example.org/bar\n[submodule \"baz\"]\nurl = https://example.org/baz\n[submodule \"bob\"]\nignore = true\n[submodule]\nactive = b*\nactive = :(exclude) baz\n\nIn here all submodules except baz (foo, bar, bob) are active. foo due to its own active flag\nand all the others due to the submodule active pathspec, which specifies that any submodule\nstarting with b except baz are also active, regardless of the presence of the .url field.\n",
                "subsections": []
            },
            "WORKFLOW FOR A THIRD PARTY LIBRARY": {
                "content": "# Add a submodule\ngit submodule add <url> <path>\n\n# Occasionally update the submodule to a new version:\ngit -C <path> checkout <new version>\ngit add <path>\ngit commit -m \"update submodule to new version\"\n\n# See the list of submodules in a superproject\ngit submodule status\n\n# See FORMS on removing submodules\n",
                "subsections": []
            },
            "WORKFLOW FOR AN ARTIFICIALLY SPLIT REPO": {
                "content": "# Enable recursion for relevant commands, such that\n# regular commands recurse into submodules by default\ngit config --global submodule.recurse true\n\n# Unlike most other commands below, clone still needs\n# its own recurse flag:\ngit clone --recurse <URL> <directory>\ncd <directory>\n\n# Get to know the code:\ngit grep foo\ngit ls-files --recurse-submodules\n\nNote\ngit ls-files also requires its own --recurse-submodules flag.\n\n# Get new code\ngit fetch\ngit pull --rebase\n\n# Change worktree\ngit checkout\ngit reset\n",
                "subsections": []
            },
            "IMPLEMENTATION DETAILS": {
                "content": "When cloning or pulling a repository containing submodules the submodules will not be checked\nout by default; you can instruct clone to recurse into submodules. The init and update\nsubcommands of git submodule will maintain submodules checked out and at an appropriate\nrevision in your working tree. Alternatively you can set submodule.recurse to have checkout\nrecursing into submodules (note that submodule.recurse also affects other Git commands, see\ngit-config(1) for a complete list).\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "git-submodule(1), gitmodules(5).\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                             GITSUBMODULES(7)",
                "subsections": []
            }
        }
    }
}