git switch
git
Syntaxe
git switch [-c <new>] <branch>La commande de git 2.23 qui ne fait que changer de branche ; elle ne réécrit jamais le contenu des fichiers, c'est le rôle de restore.
Options courantes
| Option | Signification |
|---|---|
| -c <new> | create the branch and switch to it |
| -C <new> | create it, or reset it here if it exists |
| - | go back to the branch you were on before |
| --detach <commit> | check out a commit without a branch |
| --track <remote>/<branch> | follow a remote branch |
| -m | carry uncommitted changes across by merging them |
Exemples
git switch mainmoves to main; refuses if that would clobber your edits
git switch -c feature/apicreates the branch and moves there
git switch -jumps back to the previous branch
Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait git switch ?
La commande de git 2.23 qui ne fait que changer de branche ; elle ne réécrit jamais le contenu des fichiers, c'est le rôle de restore.
Q. Comment l’écrire ?
git switch [-c <new>] <branch> — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 6 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-switch