</>
Plan du cours — 69/74

Git worktree : travailler sur plusieurs branches en parallèle

Avancé

Un worktree permet d'avoir plusieurs branches extraites simultanément, dans des dossiers différents, sans avoir à stash ou committer pour changer de branche.

# Créer un nouveau worktree pour une branche existante, dans un dossier voisin
git worktree add ../projet-hotfix hotfix/urgent

# Créer un worktree avec une nouvelle branche
git worktree add -b feature/x ../projet-feature-x

# Lister les worktrees actifs
git worktree list

# Supprimer un worktree terminé
git worktree remove ../projet-hotfix

Cas pratique : vous êtes en plein milieu d'une fonctionnalité (fichiers modifiés, pas envie de stash) quand un bug critique tombe. Plutôt que de jongler avec git stash, ouvrez un second dossier de travail :

git worktree add ../projet-hotfix main
cd ../projet-hotfix
# corriger, commiter, pousser le hotfix, sans jamais toucher à votre travail en cours