InternalsPackages

@unbound/git-worktree

@unbound/git-worktree

Typed helpers for managing Git worktrees, branches, and cleanup policies.

This package wraps core git commands, adds validation, and provides higher-level worktree management for Unbound sessions.

What It Provides

  • Worktree creation/removal/locking
  • Repository metadata inspection
  • Cleanup utilities for stale or merged worktrees
  • Disk usage and space checks
  • Safe command execution with typed results

Core Exports

ExportPurpose
createWorktree / removeWorktreeManage worktree lifecycle
listWorktrees / getWorktreeInspect existing worktrees
cleanupWorktreesCleanup based on strategy
getRepositoryInfoCollect repo metadata
WorktreeManagerOrchestrate worktrees per session

Example

import { createWorktree, cleanupWorktrees } from "@unbound/git-worktree";

await createWorktree({
  repoPath: "/path/to/repo",
  branch: "feature/abc",
  worktreePath: "/tmp/unbound/abc",
});

await cleanupWorktrees({
  repoPath: "/path/to/repo",
  strategy: "stale",
  maxAgeHours: 24,
});

Module Layout

src/
├── git.ts        # git wrappers + errors
├── worktree.ts   # worktree lifecycle helpers
├── manager.ts    # WorktreeManager orchestration
├── cleanup.ts    # cleanup strategies
├── repository.ts # repo inspection + disk usage
└── types.ts      # shared types

Development

pnpm -C packages/git-worktree build
pnpm -C packages/git-worktree test
@unbound/git-worktree