git switch
git
Uso
git switch [-c <new>] <branch>El comando de git 2.23 que solo cambia de rama; nunca reescribe el contenido de los archivos, para eso está restore.
Opciones habituales
| Opción | Significado |
|---|---|
| -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 |
Ejemplos
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
Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.
Cómo leerlo
- Los corchetes [ ] marcan una parte que puedes omitir.
- Los puntos suspensivos … indican que puedes poner varios.
- Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.
Preguntas
Q. ¿Qué hace git switch?
El comando de git 2.23 que solo cambia de rama; nunca reescribe el contenido de los archivos, para eso está restore.
Q. ¿Cómo se escribe?
git switch [-c <new>] <branch> — los corchetes marcan lo que puedes omitir.
Q. ¿Cuántas opciones vale la pena saber?
Aquí van 6; la lista completa está en man git. Este comando está en git.
Comandos relacionados
página man: man git-switch