git-architecture
Skill9 starsChanged 17 days agoApache-2.0View on GitHub
ShipIt git architecture: GitManager (per-session), RepoGit (shared bare cache + per-session local clones), credential setup, auto-commit flow, session clone lifecycle, branch naming. Load when working on git operations, the bare cache, per-session clones, credentials, or repo management.
- Reads credentials
In this repository15 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-endpointSkill
- android-buildSkill
- client-architectureSkill
- deployment-architectureSkill
- design-languageSkill
- docs-navigatorSkill
- dogfooding-shipitSkill
- frontend-design:frontend-designSkill
- prompt-architectureSkill
- server-architectureSkill
- session-containersSkill
- session-lifecycleSkill
- session-processesSkill
- testing-and-qualitySkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 64
No remote repo. A fresh git repo is initialized in the session directory:
- Very specific: line 129
After each agent turn (backend-agnostic), turn-executor.ts runs postTurnCommit() → GitManager.autoCommit(summary), broadcasts …
- Distinctive: line 147
Remove the session directory (its independent clone goes with it — nothing else to detach)
- Very specific: line 151
When a user imports a GitHub repo (POST /api/repos):
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Architecture
ShipIt uses git for version control at two levels: per-session workspace repos managed by GitManager, and a shared per-remote bare cache (from which each session gets its own independent local clone) managed by RepoGit. Both use the simple-git library.
Each session gets its own independent full clone —
git clone --localfrom the bare cache, which hardlinks objects so the clone is fast and disk-cheap. Each session owns a complete.git/and shares nothing mutable with its siblings.
Two Git Layers
GitManager (per-session)
src/server/shared/git.ts — operates on a single session's workspace directory.
Each session gets its own GitManager instance via the createGitManager(dir) factory. Used for:
init()— initialize repo with initial commit (so rollback always has a base)autoCommit(summary)— stage all + commit if anything changedlog(maxCount)— commit historyrollback(hash)— hard reset to a previous commitpush(remote, branch)— push with upstream trackingpull(remote, branch)— pull from remoteaddRemote(name, url)/getRemotes()— remote managementcheckoutNewBranch(name)/renameBranch(old, new)— branch operationsdiffSummary()— per-file diff stats for the working treediffStatVsBranch(baseBranch)— insertions/deletions vs a base branch (for PR stats)getFileAtCommit(hash, filePath)— file content at a specific commitdiffNameStatus(from, to)— changed files with status between commitsmerge(branchName)— merge with conflict detection
RepoGit (bare cache)
src/server/orchestrator/repo-git.ts — operates on a per-remote bare cache directory (one bare clone per remote URL, at {stateDir}/repo-cache/{hash}).
Used by the orchestrator to seed and refresh the cache, then cut per-session clones from it:
cloneBare(url)— bare-clone the remote into the cache dir (git clone --bare)fetchCache(ttlMs?)— fetch the remote into the bare cache (advances localrefs/heads/*); TTL-throttledcloneFromCache(sessionDir, remoteUrl?)— create a session's clone:git clone --localfrom the cache (hardlinked objects), setgc.auto=0, then resetoriginto the real remote URLgetDefaultBranch(remote)— detect main/master (tries local refs first to avoid network calls)deleteBranch(name)— delete local branchisEmpty()/createInitialCommit()— empty-repo handlingreadHead()/lastFetchAgeMs()— cache freshness checks used by the proactive pre-fetcher
Who owns the bare cache (docs/272-shared-cache-ownership)
The cache is ShipIt's own tree, owned uniformly by the orchestrator's identity, and orchestrator/shared-tree-ownership.ts enforces that rather than assuming it: fetchCache and cloneFromCache each check the cache with one lstat first and repair it if a foreign owner appears, and the boot janitor makes one deep pass over repo-cache/ and marketplace-cache/. Three production failures came out of the same unstated contract — refs that could not be locked, a chown reaching through a hardlink into the cache, and a root clone that a uid-1000 source refused once git's ownership check was armed.
Two rules when you touch any of this:
- Never
chownRecursivea tree cut from the cache.clone --localhardlinks.git/objects, and an inode has one owner across every link, so it is a chown inside the cache. UsehandWorkspaceBackToWorker(a session workspace) orhandPluginCheckoutToWorker(a plugin generation's checkout); both chown object directories and never the data files.session-fork-merge.tsis the one legitimate exception, and only because it clones with--no-hardlinks. Enforced byorchestrator/shared-tree-ownership-coverage.test.ts. - A clone needs BOTH ownership answers — source and destination. git's check tests the repository being read, and
clone --localcan only hardlink an object file the cloning identity may link. A destination-only audit cleared the site that broke production. Enforced by the two censuses inshared/git-hooks-guard-coverage.test.ts.
Debugging: a root process getting EACCES/EPERM is not impossible — read it as "the process dropped uid (docs/266) and the tree is not uniformly owned" before anything else.
Session Types and Git Setup
Standalone Session
No remote repo. A fresh git repo is initialized in the session directory:
/workspace/sessions/{uuid}/
.git/ <- independent repo
(user's code)GitManager.init() creates the repo with --initial-branch=main and an empty initial commit.
Repo-backed Session
Backed by the per-remote bare cache. The session directory is its own independent clone — a complete repo:
{stateDir}/repo-cache/{hash}/ <- bare cache (one per remote URL)
HEAD, refs/, objects/ (bare; no working tree)
{sessionsRoot}/{uuid}/workspace/ <- the session's own clone
.git/ (complete; objects hardlinked from the cache)
(checked out on a unique branch)Created via RepoGit.cloneFromCache(sessionDir, remoteUrl) (git clone --local, so objects are hardlinked — fast and disk-cheap), then the session's GitManager checks out a unique branch. Each session owns a full .git/ and shares nothing mutable with its siblings, so multiple sessions work the same repo simultaneously without conflicts.
Git Credentials
Global Git Config
src/server/orchestrator/git-config.ts sets up a global git config file via GIT_CONFIG_GLOBAL environment variable:
/credentials/.gitconfig
[user]
name = ...
email = ...
[commit]
gpgsign = false
[credential "https://github.com"]
helper = ...This config is inherited by all git operations (both GitManager and RepoGit).
CredentialStore
Two distinct things live in the credentials directory — don't conflate them:
.gitconfig— git identity (name, email), written bygit-config.tsand pointed at byGIT_CONFIG_GLOBALso every git invocation inherits it. Not part ofCredentialStore.shipit-credentials.json—CredentialStore(credential-store.ts). HoldsgithubToken,agentEnv, provider-account metadata, and app settings as fields in one JSON file, encrypted when a cipher is supplied. The older separate.github-token/.agent-env/.git-credentialsfiles are gone.
Provider subscription auth (Claude/Codex logins) is separate again — it lives in per-account filesystem roots managed by provider-account-manager.ts.
The credentials directory is mounted read-only into session containers, so workers can push/pull but not modify credentials.
GitHub Auth
src/server/orchestrator/github-auth.ts — manages GitHub token and API access. When authenticated:
- Configures git credential helper to use the stored token
- Loads GitHub user info (username, avatar) for UI display
- Enables GitHub API operations (search repos, create PRs, etc.)
Auto-Commit Flow
After each agent turn (backend-agnostic), turn-executor.ts runs postTurnCommit() → GitManager.autoCommit(summary),
broadcasts git_committed, runs the PR lifecycle card flow, and arms the auto-push LAST via
services/auto-push-scheduler.ts (debounce autoPushDebounceMs, default 0). Ordering and invariants:
CLAUDE.md → Post-turn flow.
Session Clone Lifecycle
Creation (new session on an imported repo)
createSessionDir(title)— creates the empty{uuid}/workspacedirectoryRepoGit.cloneFromCache(workspaceDir, remoteUrl)—git clone --localfrom the bare cache (hardlinked objects), setgc.auto=0, resetoriginto the real remoteGitManager.checkoutNewBranch(branchName)— unique branch off the default branch- Branch name:
{prefix}/{short-uuid}(e.g.,shipit/abc123)
- Branch name:
- Git credentials are inherited from the global config (see below)
Cleanup (session archived)
RepoGit.deleteBranch(branchName)— clean up the local branch in the cache, when applicable- Remove the session directory (its independent clone goes with it — nothing else to detach)
Repo Import Flow
When a user imports a GitHub repo (POST /api/repos):
RepoStoretracks the repo withstatus: "cloning"- Bare-clone into
{stateDir}/repo-cache/{hash}/viaRepoGit.cloneBare() - Fetch to ensure the default branch is available in the cache
- Set
status: "ready" - Warm a session for the repo (clone-from-cache + metadata, no container)
On subsequent use, the bare cache is reused (and periodically re-fetched). Each new session gets its own fresh local clone branching from the latest default branch.
Branch Naming
src/server/orchestrator/git-utils.ts:
generateBranchPrefix()returns a prefix likeshipit(configurable)- Full branch name:
{prefix}/{short-uuid} parseGitHubRemote(url)extracts owner/repo from GitHub URLs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

