Skip to main content

add_worktree

Function add_worktree 

Source
pub fn add_worktree(
    repo: &Repository,
    branch_name: &str,
    branch_type: BranchType,
    base_branch: Option<&str>,
) -> Result<WorktreeDescriptor>
Expand description

Create a new worktree for the given branch.

The worktree directory is placed under the workon root (see workon_root). Branch names containing / are supported; parent directories are created automatically and the worktree is named after the final path component.

ยงBranch types

  • BranchType::Normal โ€” uses an existing local/remote branch, or creates one from base_branch (or HEAD if base_branch is None).
  • BranchType::Orphan โ€” creates an independent branch with no shared history, seeded with an empty initial commit.
  • BranchType::Detached โ€” creates a worktree with a detached HEAD pointing to the current HEAD commit.