Skip to main content

create_worktree

Function create_worktree 

Source
pub fn create_worktree<P: AsRef<Path>>(path: P, branch: &str) -> Result<()>
Expand description

Create a new worktree at the specified path for the given branch.

If the branch already exists, it will be checked out in the new worktree. If the branch doesn’t exist, it will be created from the current HEAD.

§Arguments

  • path - The path where the worktree should be created
  • branch - The branch name to checkout or create

§Returns

  • Ok(()) - Worktree created successfully
  • Err - If creation fails (e.g., branch already checked out elsewhere)