Worktrees
Worktree operations are available via repo.worktrees (or top-level worktree functions on Repository).
List worktrees
Section titled “List worktrees”let worktrees = try repo.worktreeList()for wt in worktrees { print(wt.name, wt.path)}Add a worktree
Section titled “Add a worktree”try repo.addWorktree( named: "hotfix", path: URL(fileURLWithPath: "/path/to/hotfix"), branch: "hotfix/critical")Remove a worktree
Section titled “Remove a worktree”try repo.removeWorktree(named: "hotfix")Lock a worktree
Section titled “Lock a worktree”Locking prevents pruning and accidental removal — useful for worktrees on removable storage.
try repo.lockWorktree(named: "hotfix", reason: "On external drive")Unlock a worktree
Section titled “Unlock a worktree”try repo.unlockWorktree(named: "hotfix")