Mémo pour utiliser git worktree.
Plus fort que git stash, utile pour travailler sur un même projet dans des contextes différents, ou juste temporairement, le temps d’un fix.
Dans un projet git simple :
|
1 2 3 4 5 6 7 8 9 |
$ tree mon_projet/ mon_projet/ ├── fichier1.md └── fichier2.md $ cd mon_projet $ git status Sur la branche main rien à valider, la copie de travail est propre |
Dans le répertoire du projet :
|
1 2 3 |
$ git worktree add -b branche1 ../mon_projet-branche1 Préparation de l'arbre de travail (nouvelle branche 'branche1') HEAD est maintenant à 42beff0 Init |
On a donc 2 répertoires du même projet, mais avec des branches différentes :
|
1 2 3 4 5 6 7 8 |
$ cd .. $ ll mon_projet mon_projet-branche1 $ cd mon_projet-branche1 $ git status Sur la branche branche1 rien à valider, la copie de travail est propre |
Liste des worktree :
|
1 2 3 |
$ git worktree list -v /worktree-test/mon_projet 42beff0 [main] /worktree-test/mon_projet-branche1 42beff0 [branche1] |
Les arguments intéressants : move, delete, lock et unlock.
Doc: https://git-scm.com/docs/git-worktree![]()