worktree¶

For git-worktree(1).

Overview¶

Manage git worktrees using GitWorktreeManager (collection-level) and GitWorktreeCmd (per-worktree operations).

Examples¶

Add a worktree checked out at HEAD, then look it up — the main worktree always exists, so the list grows to two:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.worktrees.add(path=tmp_path / 'example-worktree', commit_ish='HEAD')
'HEAD is now at ...'
>>> worktrees = git.worktrees.ls()
>>> len(worktrees) >= 2
True
>>> wt = git.worktrees.get(worktree_path=worktrees[0].worktree_path)
>>> wt.worktree_path == worktrees[0].worktree_path
True

Prune stale worktree metadata:

>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.worktrees.prune()
''

API Reference¶

class libvcs.cmd.git.GitWorktreeManager
¶
class libvcs.cmd.git.GitWorktreeManager
¶

Bases: object

Traverse git worktrees with QueryList.

class libvcs.cmd.git.GitWorktreeCmd
¶
class libvcs.cmd.git.GitWorktreeCmd
¶

Bases: object

Run git commands targeting a specific worktree.