Da Anonimo (non verificato) , 29 Aprile 2026

Il problema risolto dai worktree

Sei a meta feature quando arriva una richiesta urgente di hotfix. Stash o cambio contesto sono rischiosi e lenti. I worktree consentono di estrarre branch aggiuntivi in directory separate, tutti condividendo un database oggetti sottostante.

Aggiungere un worktree

git worktree add ../hotfix main
cd ../hotfix
git checkout -b hotfix/urgent
cd -
git worktree remove ../hotfix

Elencare e ripulire

git worktree list
git worktree list --porcelain
git worktree prune
git worktree remove ../old-feature
git worktree lock ../release
git worktree unlock ../release

Worktree distaccati

git worktree add --detach ../v1.0 v1.0.0

Regole di condivisione branch

Lo stesso branch non puo essere checkout in due worktree contemporaneamente.

Casi d'uso

  • Build CI di lunga durata in un worktree mentre si continua a programmare.
  • Confronto fianco a fianco di due branch nell'editor.
  • Bisect in un worktree mentre il checkout principale resta fermo.

Configurazione

git config --worktree user.email [email protected]

Errori comuni

Rimuovere una directory worktree con rm -rf invece di git worktree remove lascia metadati stantii.