{
    "slug": "git_submodules",
    "term": "Git Submodules & Monorepo Alternatives",
    "category": "git",
    "difficulty": "intermediate",
    "short": "Git submodules embed one repo inside another — complex to manage. Composer packages, git subtrees, and monorepos are better alternatives for most PHP projects.",
    "long": "Git submodules: a repository nested inside another, pinned to a specific commit. Common problems: easy to forget to commit submodule updates, new contributors miss git submodule update --init, detached HEAD confusion, and complex CI setup. Alternatives: git subtree (merges subtree history into main repo, no nested .git), monorepo (all code in one repo with build tool), Composer packages (proper versioning + dependency resolution). For PHP: Composer with a private Packagist is almost always better than submodules.",
    "aliases": [
        "git submodule",
        "monorepo",
        "git subtree"
    ],
    "tags": [
        "git",
        "devops",
        "architecture"
    ],
    "misconception": "Git submodules are the best way to share code between repositories — Composer packages with semantic versioning provide explicit versioning, changelogs, and proper dependency resolution that submodules cannot.",
    "why_it_matters": "Teams managing shared libraries as submodules spend significant time on submodule updates, detached HEAD confusion, and CI failures — Composer packages solve the same problem with far less friction.",
    "common_mistakes": [
        "Committing changes to submodule without updating the parent repo's pointer",
        "Forgetting git submodule update --init on fresh clone — builds fail",
        "Using submodules for external dependencies — use Composer/npm instead",
        "No --recursive flag in CI clone — submodules are empty"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "dependency_management",
        "conventional_commits_tooling",
        "github_actions_deep"
    ],
    "prerequisites": [
        "git_workflows_compared",
        "dependency_management",
        "composer"
    ],
    "refs": [
        "https://git-scm.com/book/en/v2/Git-Tools-Submodules"
    ],
    "bad_code": "# Developer updates submodule, forgets to update parent:\ngit -C shared-lib commit -m 'Add feature'\n# Forgets: cd .. && git add shared-lib && git commit\n# Other developers: still get old version\n\n# New clone:\ngit clone repo && ls shared-lib/ # Empty! Forgot --recursive",
    "good_code": "# Composer private package instead:\n# composer.json:\n# {\"require\": {\"company/shared-lib\": \"^1.3\"}}\n\n# Developer A releases update:\n# git tag v1.3.0 && git push --tags\n# Consumer updates:\n# composer update company/shared-lib\n# Explicit version, CHANGELOG, proper dep resolution",
    "quick_fix": "Prefer Composer packages over git submodules for PHP dependencies — submodules have a poor developer experience; use submodules only for shared configuration or infrastructure repos that aren't Composer packages",
    "severity": "low",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/git_submodules",
        "html_url": "https://codeclaritylab.com/glossary/git_submodules",
        "json_url": "https://codeclaritylab.com/glossary/git_submodules.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Git Submodules & Monorepo Alternatives](https://codeclaritylab.com/glossary/git_submodules) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/git_submodules"
            }
        }
    }
}