This page introduces Zed's Git integration at a system level: its crate structure, how the UI, project service, and repository abstraction layers interact, and how state flows between them.
Zed's Git integration is spread across three primary layers, with additional support in the filesystem and protocol crates:
| Layer | Crate | Primary Types |
|---|---|---|
| UI | crates/git_ui | GitPanel, ProjectDiff, CommitModal, CommitView, BranchPicker |
| Project Service | crates/project | GitStore, Repository, BufferGitState, BranchDiff, ConflictSet |
| Repository Abstraction | crates/git | GitRepository trait, Oid, Branch, CommitData, GitStatus |
| Filesystem / Testing | crates/fs | FakeGitRepository, FakeGitRepositoryState |
| Protocol | crates/proto | UpdateRepository, UpdateDiffBases, GitBranchesResponse |
The git crate defines core data types such as Branch, FileStatus, and CommitData crates/git/src/repository.rs82-114 and the GitRepository trait crates/git/src/repository.rs166 The project crate owns the GitStore entity which manages one or more Repository entities crates/project/src/git_store.rs99-103 The git_ui crate builds visible panels and modals on top of that crates/git_ui/src/git_ui.rs88-101
Diagram: Git Integration — Crates and Key Entities
Sources: crates/git_ui/src/git_panel.rs1-17 crates/project/src/git_store.rs99-125 crates/git/src/repository.rs166 crates/fs/src/fake_git_repo.rs166
GitRepository TraitDefined in crates/git/src/repository.rs166 this trait is the primary abstraction for a git repository. It decouples the application from the underlying Git implementation (typically libgit2 or a CLI-based backend).
Key methods defined in the trait and implemented by backends (like FakeGitRepository):
| Method | Purpose |
|---|---|
load_blob_content(oid) | Reads content for a specific object ID crates/git/src/repository.rs171 |
load_commit_template() | Retrieves the git commit template crates/git/src/repository.rs167 |
set_index_text(path, content) | Writes a file's staged content crates/git/src/repository.rs186-190 |
load_commit(sha, cx) | Retrieves diff data for a specific commit crates/git/src/repository.rs178-182 |
Repository EntityRepository is a GPUI Entity managed by the GitStore crates/project/src/git_store.rs103 It acts as the primary handle for UI components to interact with a specific git repository. It provides access to branch lists, stashes, and remote status via RepositoryEvent crates/project/src/git_store.rs67
GitStore EntityGitStore crates/project/src/git_store.rs99-112 is owned by Project and coordinates all Git state:
repositories: HashMap<RepositoryId, Entity<Repository>> crates/project/src/git_store.rs103BufferGitState per open buffer, tracking unstaged_diff, staged_diff, and uncommitted_diff crates/project/src/git_store.rs109 crates/project/src/git_store.rs121-125hunk_staging_operation_count to ensure index text is synchronized with disk crates/project/src/git_store.rs142-143For details, see Git Store Architecture.
Diagram: Hunk Staging Flow
Sources: crates/project/src/git_store.rs121-143 crates/fs/src/fake_git_repo.rs186-191
GitPanelGitPanel crates/git_ui/src/git_panel.rs194 is the primary Git workspace panel. It provides actions for:
ToggleStaged) crates/git/src/git.rs45ToggleTreeView) crates/git_ui/src/git_panel.rs148NextEntry, PreviousEntry) crates/git_ui/src/git_panel.rs128-130For details, see Git Panel and UI.
ProjectDiffProjectDiff crates/git_ui/src/project_diff.rs9 is a workspace component showing changed files across the project. It integrates with BufferDiff to visualize hunks and supports "Branch Diff" modes to compare against a base ref.
BranchPickerBranchPicker crates/git_ui/src/branch_picker.rs38 is the UI delegate for the branch selection interface. It fetches the branch list from the Repository and handles checkout, creation, or deletion actions.
CommitViewCommitView crates/git_ui/src/commit_view.rs42 displays details of a specific commit, including its diff. It allows users to view commit metadata, author information, and file changes.
For details on diffing and staging, see Diff System and Staging.
When a project is shared, git state is replicated via protobuf messages crates/proto/proto/git.proto1-2
Key protobuf message types:
| Message | Purpose |
|---|---|
UpdateRepository | Sync repository state including branches, stashes, and file statuses crates/proto/proto/git.proto118-140 |
UpdateDiffBases | Synchronizes staged and committed text for a buffer between peers crates/proto/proto/git.proto12-38 |
OpenUnstagedDiff | Requests the host to provide the staged text for a specific buffer crates/proto/proto/git.proto40-43 |
GitGetBranches | Request the list of branches from the host crates/proto/proto/git.proto179-183 |
The GitStore handles synchronization between the local editor state and the host's git state, tracking remote peer diffs in shared_diffs crates/project/src/git_store.rs111
Diagram: Git-related Modules in Zed
Sources: crates/git_ui/src/git_ui.rs30-63 crates/project/src/git_store.rs1-5 crates/git/src/git.rs1-7
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.