# gitgitgadget/git architecture

> Architecture diagram of the GitHub repository gitgitgadget/git, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gitgitgadget/git
- Repository: https://github.com/gitgitgadget/git

## Overview

Git is a distributed revision-control system exposed through a command-line interface, with high-level repository operations and lower-level object and reference management. The README establishes the product and its command-oriented use; the sampled source shows repository initialization and its dependencies, plus object-database and reference-storage implementation areas. Many major commands and subsystems are present in the tree but were not sampled, so their internal call paths are not asserted here.

Main entry points: [`repository.c`](https://github.com/gitgitgadget/git/blob/master/repository.c) (Repository setup), [`odb/source-files.c`](https://github.com/gitgitgadget/git/blob/master/odb/source-files.c) (File object store), [`odb.h`](https://github.com/gitgitgadget/git/blob/master/odb.h) (Object database), [`refs.h`](https://github.com/gitgitgadget/git/blob/master/refs.h) (Reference API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["Git commands"]
  node_gitcli["Git CLI<br/>[git.c]"]
  node_checkout["Checkout worker<br/>[checkout--worker.c]"]
  node_diff["Diff engine<br/>[diff.c]"]
  node_merge["Merge engine<br/>[merge-ort.c]"]
  node_network["Transport<br/>[transport.c]"]
  node_branch["Branch operations<br/>[branch.c]"]
  node_history["Revision walking<br/>[revision.h]"]
end

subgraph group_repository["Repository state"]
  node_repo_init["Repository setup<br/>[repository.c]"]
  node_repo_state["Repository state<br/>[repository.h]"]
  node_config["Configuration<br/>[config.h]"]
  node_index[("Index cache<br/>[read-cache.c]")]
  node_directory["Worktree scanning<br/>[dir.h]"]
end

subgraph group_storage["Object storage"]
  node_odb[("Object database<br/>[odb.h]")]
  node_odb_files[("File object store<br/>[source-files.c]")]
  node_object_model["Object model<br/>[object.h]"]
  node_pack_objects["Pack creation<br/>[pack-objects.c]"]
end

subgraph group_references["References"]
  node_refs_api["Reference API<br/>[refs.h]"]
  node_refs_files[("Files backend<br/>[files-backend.c]")]
  node_refs_reftable[("Reftable backend<br/>[reftable-backend.c]")]
end

subgraph group_foundation["Core primitives"]
  node_hash["Hash primitives<br/>[hash.h]"]
  node_paths["Path utilities<br/>[abspath.h]"]
  node_buffers["String buffers<br/>[strbuf.h]"]
  node_processes["Process execution<br/>[run-command.h]"]
  node_trace["Trace events<br/>[trace2.h]"]
  node_settings["Repository settings<br/>[repo-settings.h]"]
  node_environment["Environment<br/>[environment.h]"]
  node_compat["Platform compatibility<br/>[git-compat-util.h]"]
end

node_user(("Git user"))

node_user -->|"runs commands"| node_gitcli
node_repo_init -->|"initializes storage"| node_odb
node_repo_init -->|"reads configuration"| node_config
node_repo_init -->|"initializes"| node_repo_state
node_odb_files -->|"implements access"| node_odb
node_odb_files -->|"uses object files"| node_object_model
node_odb_files -->|"uses pack support"| node_pack_objects
node_refs_files -->|"implements operations"| node_refs_api
node_refs_reftable -.->|"implements operations"| node_refs_api

click node_gitcli "https://github.com/gitgitgadget/git/blob/master/git.c"
click node_checkout "https://github.com/gitgitgadget/git/blob/master/builtin/checkout--worker.c"
click node_repo_init "https://github.com/gitgitgadget/git/blob/master/repository.c"
click node_repo_state "https://github.com/gitgitgadget/git/blob/master/repository.h"
click node_config "https://github.com/gitgitgadget/git/blob/master/config.h"
click node_odb "https://github.com/gitgitgadget/git/blob/master/odb.h"
click node_odb_files "https://github.com/gitgitgadget/git/blob/master/odb/source-files.c"
click node_refs_api "https://github.com/gitgitgadget/git/blob/master/refs.h"
click node_refs_files "https://github.com/gitgitgadget/git/blob/master/refs/files-backend.c"
click node_refs_reftable "https://github.com/gitgitgadget/git/blob/master/refs/reftable-backend.c"
click node_object_model "https://github.com/gitgitgadget/git/blob/master/object.h"
click node_pack_objects "https://github.com/gitgitgadget/git/blob/master/builtin/pack-objects.c"
click node_index "https://github.com/gitgitgadget/git/blob/master/read-cache.c"
click node_directory "https://github.com/gitgitgadget/git/blob/master/dir.h"
click node_diff "https://github.com/gitgitgadget/git/blob/master/diff.c"
click node_merge "https://github.com/gitgitgadget/git/blob/master/merge-ort.c"
click node_network "https://github.com/gitgitgadget/git/blob/master/transport.c"
click node_branch "https://github.com/gitgitgadget/git/blob/master/builtin/branch.c"
click node_history "https://github.com/gitgitgadget/git/blob/master/revision.h"
click node_hash "https://github.com/gitgitgadget/git/blob/master/hash.h"
click node_paths "https://github.com/gitgitgadget/git/blob/master/abspath.h"
click node_buffers "https://github.com/gitgitgadget/git/blob/master/strbuf.h"
click node_processes "https://github.com/gitgitgadget/git/blob/master/run-command.h"
click node_trace "https://github.com/gitgitgadget/git/blob/master/trace2.h"
click node_settings "https://github.com/gitgitgadget/git/blob/master/repo-settings.h"
click node_environment "https://github.com/gitgitgadget/git/blob/master/environment.h"
click node_compat "https://github.com/gitgitgadget/git/blob/master/git-compat-util.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gitcli,node_checkout,node_diff,node_merge,node_network,node_branch,node_history,node_user toneBlue
class node_repo_init,node_repo_state,node_config,node_index,node_directory toneAmber
class node_odb,node_odb_files,node_object_model,node_pack_objects toneMint
class node_refs_api,node_refs_files,node_refs_reftable toneRose
class node_hash,node_paths,node_buffers,node_processes,node_trace,node_settings,node_environment,node_compat toneIndigo
```

## Components

### Git commands

- [Git CLI](https://github.com/gitgitgadget/git/blob/master/git.c): `git.c`
- [Checkout worker](https://github.com/gitgitgadget/git/blob/master/builtin/checkout--worker.c): `builtin/checkout--worker.c`
- [Diff engine](https://github.com/gitgitgadget/git/blob/master/diff.c): `diff.c`
- [Merge engine](https://github.com/gitgitgadget/git/blob/master/merge-ort.c): `merge-ort.c`
- [Transport](https://github.com/gitgitgadget/git/blob/master/transport.c): `transport.c`
- [Branch operations](https://github.com/gitgitgadget/git/blob/master/builtin/branch.c): `builtin/branch.c`
- [Revision walking](https://github.com/gitgitgadget/git/blob/master/revision.h): `revision.h`

### Repository state

- [Repository setup](https://github.com/gitgitgadget/git/blob/master/repository.c): `repository.c`
- [Repository state](https://github.com/gitgitgadget/git/blob/master/repository.h): `repository.h`
- [Configuration](https://github.com/gitgitgadget/git/blob/master/config.h): `config.h`
- [Index cache](https://github.com/gitgitgadget/git/blob/master/read-cache.c): `read-cache.c`
- [Worktree scanning](https://github.com/gitgitgadget/git/blob/master/dir.h): `dir.h`

### Object storage

- [Object database](https://github.com/gitgitgadget/git/blob/master/odb.h): `odb.h`
- [File object store](https://github.com/gitgitgadget/git/blob/master/odb/source-files.c): `odb/source-files.c`
- [Object model](https://github.com/gitgitgadget/git/blob/master/object.h): `object.h`
- [Pack creation](https://github.com/gitgitgadget/git/blob/master/builtin/pack-objects.c): `builtin/pack-objects.c`

### References

- [Reference API](https://github.com/gitgitgadget/git/blob/master/refs.h): `refs.h`
- [Files backend](https://github.com/gitgitgadget/git/blob/master/refs/files-backend.c): `refs/files-backend.c`
- [Reftable backend](https://github.com/gitgitgadget/git/blob/master/refs/reftable-backend.c): `refs/reftable-backend.c`

### Core primitives

- [Hash primitives](https://github.com/gitgitgadget/git/blob/master/hash.h): `hash.h`
- [Path utilities](https://github.com/gitgitgadget/git/blob/master/abspath.h): `abspath.h`
- [String buffers](https://github.com/gitgitgadget/git/blob/master/strbuf.h): `strbuf.h`
- [Process execution](https://github.com/gitgitgadget/git/blob/master/run-command.h): `run-command.h`
- [Trace events](https://github.com/gitgitgadget/git/blob/master/trace2.h): `trace2.h`
- [Repository settings](https://github.com/gitgitgadget/git/blob/master/repo-settings.h): `repo-settings.h`
- [Environment](https://github.com/gitgitgadget/git/blob/master/environment.h): `environment.h`
- [Platform compatibility](https://github.com/gitgitgadget/git/blob/master/git-compat-util.h): `git-compat-util.h`

### Other components

- **Git user**

## Connections

- Git user → Git CLI: runs commands
- Repository setup → Object database: initializes storage (evidence: `repository.c`)
- Repository setup → Configuration: reads configuration (evidence: `repository.c`)
- Repository setup → Repository state: initializes (evidence: `repository.c`)
- File object store → Object database: implements access (evidence: `odb/source-files.c`)
- File object store → Object model: uses object files (evidence: `odb/source-files.c`)
- File object store → Pack creation: uses pack support (evidence: `odb/source-files.c`)
- Files backend → Reference API: implements operations (evidence: `refs/files-backend.c`)
- Reftable backend → Reference API: implements operations
