Início·Comandos de terminal

git switch

git

Uso

git switch [-c <new>] <branch>

O comando do git 2.23 que apenas troca de branch; nunca reescreve o conteúdo dos arquivos, isso é papel do restore.

Opções comuns

OpçãoSignificado
-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
-mcarry uncommitted changes across by merging them

Exemplos

git switch main

moves to main; refuses if that would clobber your edits

git switch -c feature/api

creates the branch and moves there

git switch -

jumps back to the previous branch

O confuso é que desfazer tem várias formas: mover para onde um branch aponta não é o mesmo que criar um commit que reverte.

Como ler

  • Os colchetes [ ] marcam uma parte que você pode omitir.
  • As reticências … indicam que você pode listar vários.
  • As opções diferenciam maiúsculas: em alguns comandos -r e -R fazem coisas diferentes.

Perguntas

Q. O que git switch faz?

O comando do git 2.23 que apenas troca de branch; nunca reescreve o conteúdo dos arquivos, isso é papel do restore.

Q. Como se digita?

git switch [-c <new>] <branch> — os colchetes marcam o que você pode omitir.

Q. Quantas opções vale a pena saber?

Aqui estão 6; a lista completa está em man git. Este comando fica em git.

Comandos relacionados

página man: man git-switch