5 releases (3 breaking)

new 0.4.0 May 8, 2026
0.3.0 May 6, 2026
0.2.1 Apr 17, 2026
0.2.0 Apr 15, 2026
0.1.0 Mar 14, 2026

#2659 in Development tools


Used in git-workon

MIT license

140KB
2.5K SLoC

Core library for git-workon, an opinionated git worktree workflow tool.

This crate (published as workon) provides the building blocks for cloning, initialising, and managing git repositories in a bare-repo-plus-worktrees layout.

Key types

Key functions

Function Description
clone Clone a remote repository into the worktrees layout
init Initialise a new bare repository with an initial commit
get_repo Discover and open a bare repository from a path
get_worktrees List all worktrees in a repository
add_worktree Create a new worktree (normal, orphan, or detached)
find_worktree Locate a worktree by name or branch
current_worktree Return the worktree containing the current directory
move_worktree Atomically rename a worktree and its branch
copy_untracked Copy local (git-unmanaged) files between worktrees
workon_root Resolve the directory that holds all worktrees

Example

use workon::{get_repo, get_worktrees, add_worktree, BranchType};

let repo = get_repo(None)?;

for wt in get_worktrees(&repo)? {
    println!("{}: {}", wt.name().unwrap_or("?"), wt.path().display());
}

let wt = add_worktree(&repo, "my-feature", BranchType::Normal, None, false)?;
println!("Created: {}", wt.path().display());

workon

Core library for git-workon: an opinionated git worktree workflow tool.

Published on crates.io as git-workon-lib (library name: workon).

Usage

[dependencies]
git-workon-lib = "0.1"
use workon::{get_repo, get_worktrees, add_worktree, BranchType};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let repo = get_repo(None)?;

    // List all worktrees
    for wt in get_worktrees(&repo)? {
        println!("{}: {}", wt.name().unwrap_or("?"), wt.path().display());
    }

    // Create a new worktree
    let wt = add_worktree(&repo, "my-feature", BranchType::Normal, None)?;
    println!("Created worktree at {}", wt.path().display());

    Ok(())
}

API docs

Full API documentation is on docs.rs.

Dependencies

~24–37MB
~603K SLoC