Git Worktrees
Git worktrees let you check out multiple branches in separate directories sharing one .git database. Rust developers use them for parallel PR reviews, hotfix branches, and long cargo build runs without stashing.
Busca en todas las páginas de la documentación
Git worktrees let you check out multiple branches in separate directories sharing one .git database. Rust developers use them for parallel PR reviews, hotfix branches, and long cargo build runs without stashing.
# From main repo
git worktree add ../billing-api-review origin/feat/billing-tax
cd ../billing-api-review
cargo test -q
# Remove when done
cd ../billing-api
git worktree remove ../billing-api-reviewWhen to reach for this:
release/* while developing on maingit worktree list
git worktree add -b hotfix/2.5.1 ../hotfix v2.5.0
cd ../hotfix
cargo build --release
./target/release/my-service --version
git worktree prune # clean stale metadataWhat this demonstrates:
target/ (unless shared via config)prune removes invalid worktree records~/code/billing-api/ # main development (feat/*)
~/code/billing-api-review/ # ephemeral PR checkout
~/code/billing-api-hotfix/ # production hotfix
Point editor to one worktree at a time or use multi-root workspace sparingly - each tree loads separate target/ for correct diagnostics.
git worktree list weekly; remove merged PR trees.target via symlink - can confuse incremental builds across branches. Fix: separate target per tree unless intentional sccache.worktree remove.| Alternative | Use When | Don't Use When |
|---|---|---|
git stash | Quick context switch | Long builds to replay |
Second git clone | Complete isolation | Disk and fetch duplication |
| Docker dev container | Reproducible env | Simple review |
Typically 2-4 active; prune beyond that.
Supported; initialize submodules per worktree after add.
Advanced: bare central repo with all worktrees as sibling dirs.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026