Retour au cours

stashes et worktrees

Mettez de côté des modifications et ouvrez un second arbre pour corriger ailleurs.

objectifs d’apprentissage

  • Créer/apply un stash.
  • Lister/clean.
  • Créer un worktree.

prérequis

  • Repo avec changements non commités.
  • Espace disque.

notions clés

  • stash push/list/pop.
  • worktree add/list/remove.
  • Isolation.

démonstration guidée

étape 1

Créer et appliquer un stash.

echo "temp" >> TODO.txt
git add TODO.txt
git stash push -m "travail en cours"
git stash list
git stash pop

étape 2

Créer un worktree pour hotfix.

git worktree add ../hotfix main
ls ../hotfix

exercice

Faites un commit dans le worktree hotfix.

correction

Commit rapide.

cd ../hotfix && touch fix.txt && git add fix.txt && git commit -m "fix: correctif"

quiz éclair

  1. À quoi sert worktree ?
  • a) Plusieurs branches en parallèle, dossiers séparés.
  • b) Chiffrement.
  • c) Compression.

ressources