Skip to main content

create_worktree

Function create_worktree 

Source
pub fn create_worktree(
    repo: &Path,
    ref_name: &str,
    worktree_path: &Path,
) -> Result<()>
Expand description

Create a detached worktree at worktree_path pointing at ref_name.

ref_name is resolved via resolve_committish first, so a bare branch name that only exists as a remote-tracking ref (every branch except the default one, in a fresh clone) still checks out correctly instead of failing with “invalid reference”.

§Errors

Returns an error if ref_name cannot be resolved or git worktree add fails.