The Problem

Developers who spin up many Git worktrees waste disk space and suffer from slow checkout times. On filesystems that do not support reflinks, each worktree copies the entire repository, creating a new copy of every file even when only a few differ.

What This Does

git-twig creates lightweight, copy‑on‑write (CoW) worktrees. The command line tool in crates/git-twig/src/main.rs dispatches to the library in crates/git-twig/src/lib.rs, which in turn calls crates/git-twig/src/native.rs to perform the CoW operation. Files that are unchanged are hard‑linked; only local modifications, ignored files, or files on unsupported filesystems are copied. The tool verifies the integrity of the copied content against the requested commit, writes all staged changes under twigs/staging, and removes the staging area on success.

The project ships a CLI, a set of benchmarks in bench/, and a web UI in sites/twig.leostera.dev/ that visualises benchmark results.

How It Is Wired

Entry point – cargo run -p git-twig starts crates/git-twig/src/main.rs. From there, the Command enum (defined in the same file) routes to lib::run in crates/git-twig/src/lib.rs. run calls native::create_worktree when the new subcommand is used. create_worktree performs the following sequence:

  1. snapshot::take_snapshot ( crates/git-twig/src/snapshot.rs ) records the source tree’s state.
  2. native::link_or_copy ( crates/git-twig/src/native.rs ) walks the tree, hard‑links unchanged files and copies only the differences.
  3. staging::apply_staging ( crates/git-twig/src/staging.rs ) writes local changes to the destination while keeping them isolated.
  4. On success, staging::clean removes the staging directory; on failure, the staging area is left for inspection.

Each of these modules touches only the filesystem; none make external network calls. The benchmark harness in crates/twig-bench/src/main.rs drives a series of git-twig commands and records timings in bench/results/.

How To Use It

Setup

git clone https://github.com/moses-y/git-twig
cd git-twig
cargo install --path crates/git-twig --locked

The binary is installed as git-twig.

Configuration No additional config files are required. If you want to force the native CoW backend, set TWIG_TRACE=1 to see which filesystem path is used.

Running

git -C <repo> twig new -b feature/foo <target> <commit>
git -C <repo> twig list

The new command creates a CoW worktree at <target>. The list command displays registered worktrees.

For developers, git twig skill prints the bundled Rust skill, located in crates/git-twig/src/help.rs.

Real‑World Use

A CI system that spins up many lightweight agents can call git-twig new -b test/<id> ../worktree <commit> before each job. The job then runs inside the worktree, writes test results, and the agent cleans up without duplicating the repository.

Code Health & Issues

  • Tests – crates/git-twig/tests/worktrees.rs covers creation, failure, and cleanup paths.
  • CI – .github/workflows/ci.yml runs on Linux images with Btrfs and XFS, ensuring native CoW support.
  • Licensing – LICENSE is MIT; no unlicensed dependencies.
  • Missing – No Dockerfile or CI for macOS; the project relies on the user’s native environment.

No static analysis warnings were found in the current cargo clippy run.

The Bottom Line

git-twig delivers a concise, Rust‑based CLI that reduces worktree disk usage by up to 90 % on supported filesystems while maintaining correctness. It is well‑tested on Linux and comes with a benchmark suite that quantifies the trade‑offs. Teams that routinely create many temporary worktrees—such as CI pipelines or agent‑based workflows—will benefit most; on unsupported filesystems the tool falls back to standard git worktree.