{
    "slug": "git_internals",
    "term": "Git Internals",
    "category": "git",
    "difficulty": "advanced",
    "short": "Git stores all data as content-addressed objects (blobs, trees, commits, tags) in a directed acyclic graph — understanding this explains every git command's behaviour.",
    "long": "Git's object model: blobs store file content, trees store directory listings, commits point to a tree plus parent commits and metadata, tags point to commits. Every object is named by the SHA-1 hash of its content. Branches and tags are simply pointers (refs) to commit hashes. HEAD points to the current branch or commit. This model explains why branches are cheap (just a file with a hash), why git is fast (content addressing), and why history rewriting changes hashes.",
    "aliases": [
        "git object model",
        "git DAG",
        "git plumbing"
    ],
    "tags": [
        "git",
        "version-control",
        "internals"
    ],
    "misconception": "Git stores file diffs — git stores complete snapshots of files (blobs) at each commit; deltas are only used in packfiles for storage efficiency.",
    "why_it_matters": "Understanding git's object model explains why rebase changes commit hashes, why force push is dangerous, and how to recover 'deleted' commits with reflog.",
    "common_mistakes": [
        "Thinking git stores diffs — it stores full snapshots; packfiles compress them later.",
        "Not understanding that branch deletion does not delete commits — unreferenced commits are garbage collected eventually.",
        "Not using git cat-file to inspect objects when debugging — the plumbing commands reveal what high-level commands hide.",
        "Not understanding that a merge commit has two parents — this is what makes merge vs rebase history different."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "git_rebase_vs_merge",
        "git_reflog",
        "git_tags"
    ],
    "prerequisites": [
        "git_workflows_compared",
        "git_bisect",
        "version_control"
    ],
    "refs": [
        "https://git-scm.com/book/en/v2/Git-Internals-Git-Objects"
    ],
    "bad_code": "# Losing work by assuming branch deletion removes commits:\ngit branch -D feature/experiment\n# The commits still exist! They are just unreferenced.\n# Recover with: git reflog | grep 'feature/experiment'\n# git checkout -b recovered <hash>",
    "good_code": "# Inspect git objects directly:\ngit cat-file -t HEAD        # Shows type: commit\ngit cat-file -p HEAD        # Shows: tree, parent, author, message\ngit cat-file -p HEAD^{tree} # Shows directory listing\ngit log --graph --oneline --all  # Visualise the DAG",
    "quick_fix": "Understanding git objects (blob, tree, commit, tag) explains why git operations are fast — commits are just pointers to tree snapshots, not diffs; this explains why branches are cheap and merges are efficient",
    "severity": "info",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/git_internals",
        "html_url": "https://codeclaritylab.com/glossary/git_internals",
        "json_url": "https://codeclaritylab.com/glossary/git_internals.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 Internals](https://codeclaritylab.com/glossary/git_internals) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/git_internals"
            }
        }
    }
}