Skip to content

Worktrees

Worktree operations are available via repo.worktrees (or top-level worktree functions on Repository).

let worktrees = try repo.worktreeList()
for wt in worktrees {
print(wt.name, wt.path)
}
try repo.addWorktree(
named: "hotfix",
path: URL(fileURLWithPath: "/path/to/hotfix"),
branch: "hotfix/critical"
)
try repo.removeWorktree(named: "hotfix")

Locking prevents pruning and accidental removal — useful for worktrees on removable storage.

try repo.lockWorktree(named: "hotfix", reason: "On external drive")
try repo.unlockWorktree(named: "hotfix")