¿Cuál es la diferencia entre "git branch" y "git checkout -b"?
Usé git checkout -b
para crear una nueva rama. Creo que git branch
, hace lo mismo.
¿Cómo difieren estos dos comandos, si es que difieren en absoluto?
7 answers
git checkout -b BRANCH_NAME
crea una nueva rama y comprueba la nueva rama mientras que git branch BRANCH_NAME
crea una nueva rama pero te deja en la misma rama.
En otras palabras git checkout -b BRANCH_NAME
hace lo siguiente por ti.
git branch BRANCH_NAME # create a new branch
git checkout BRANCH_NAME # then switch to the new branch
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-05 00:23:35
git branch
crea la rama pero usted permanece en la rama actual que ha comprobado.
git checkout -b
crea una rama y la comprueba.
Es la abreviatura de:
git branch name
git checkout name
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-02 21:53:44
-
git branch
: Muestra todas sus ramas -
git branch newbranch
: Crea una nueva rama -
git checkout -b newbranch
: Crea una nueva rama y cambia a esa rama inmediatamente. Esto es lo mismo quegit branch newbranch
seguido degit checkout newbranch
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-05 17:35:51
Sintaxis completa:
git checkout -b [NEW_BRANCH] [FROM_BRANCH]
El [FROM_BRANCH] es opcional. Si no hay FROM_BRANCH, git usará la rama actual.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-05 02:28:38
También hay otra bandera para mencionar, que es relativa a estos..
git checkout -B BRANCH_NAME
Este es un comando muy útil que he estado usando recientemente. Este comando comprueba la rama que especifique, y restablece la rama basada en la rama fuente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-03 15:50:39
Hay formas de ambos comandos que son similares (mirando git-scm docs Versión 2.11.1):
git branch <branchname> <start-point>
Y
git checkout -b <new_branch> <start_point>
El último ejecutando el comando branch primero y luego agregando el checkout. En esa forma se hace referencia explícitamente al documento de git-branch:
Al especificar -b se crea una nueva rama como si git-branch[2] fueron llamados y luego se retiraron
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-21 13:59:59
Esencialmente:
A-git branch te permite crear una rama simple y llanamente.
B-git checkout-b te permite crear una rama y cambiar a ella al mismo tiempo.
¿Cuándo usarás cuál ? 1-git branch cuando quieres crear una rama pero permanecer en la rama actual. 2-git checkout-b cuando quieras crear y cambiar. Si nos fijamos en que es intuitivo para crear una rama y cambiar a ella. Así que la elección es tuya:)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-19 14:58:56