pub fn add_worktree(
repo: &Repository,
branch_name: &str,
explicit_worktree_name: Option<&str>,
branch_type: BranchType,
base_branch: Option<&str>,
lock: bool,
) -> 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.
When explicit_worktree_name is Some, that value is used as the worktree
directory name and filesystem path instead of deriving it from branch_name.
This allows the worktree directory and the branch to have different names.
ยงBranch types
BranchType::Normalโ uses an existing local branch, creates a local branch from a matching remote tracking branch (setting upstream automatically), or creates a new branch frombase_branch(or HEAD ifbase_branchisNone).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.