Como posso mudar para outro ramo no git?

Qual destas linhas está correcta?
git checkout 'another_branch'

Ou

git checkout origin 'another_branch'

Ou

git checkout origin/'another_branch'

E qual é a diferença entre estas linhas?
Author: Benyamin Jafari, 2017-12-04

4 answers

Se another_branch já existe localmente e você não está neste ramo, então git checkout another_branch muda para o ramo.

Se another_branch não existe mas origin/another_branch existe, então {[1] } é equivalente a git checkout -b another_branch origin/another_branch;git branch -u origin/another_branch. Isso é criar {[[0]} a partir de origin/another_branch e definir origin/another_branch Como O montante de another_branch.

Se nenhum deles existir, git checkout another_branch devolve um erro.

git checkout origin another_branch retorna erro na maioria dos casos. Se origin é uma revisão e {[[0]} é um ficheiro, então verifica o ficheiro dessa revisão, mas provavelmente não é o que esperavas. origin é principalmente utilizado em:git fetch, git pull e git push Como remoto, um nome falso do url do repositório remoto.

git checkout origin/another_branch tem sucesso se origin/another_branch existir. Leva a estar em estado de cabeça separada, não em qualquer ramo. Se você fizer novos commits, os novos commits não são acessíveis a partir de quaisquer branches existentes e nenhum dos branches será atualizado.

 22
Author: ElpieKay, 2017-12-05 01:22:31
A mudar para outro ramo na git. Resposta directa,

Git-checkout-Switch branches ou repor os ficheiros da árvore de trabalho

git fetch origin         <----this will fetch the branch
git checkout branch_name <--- Switching the branch

Antes de mudar a ramificação certifique-se de que não tem nenhum ficheiro modificado, nesse caso, pode enviar as alterações ou pode escondê-las.

 7
Author: danglingpointer, 2017-12-04 11:23:19

[git checkout "branch_name"]

É outra maneira de dizer:

[git checkout -b branch_name origin/branch_name]

No caso de" branch_name " existir apenas remotamente.

[git checkout -b branch_name origin/branch_name] é útil no caso de ter vários comandos.

Em relação a [{[[3]}] Não tenho a certeza se isto é possível, AFAK você pode fazer isto usando o comando" fetch" -- [git fetch origin 'another_branch']

 2
Author: Mehdi, 2018-04-27 10:52:08

Verificar:: git branch-a

Se você está recebendo apenas um ramo. Então faz por baixo dos degraus.

Passo 1: : configuração git -- list Passo 2:: git config --unset remote.origem.fetch
Passo 3:: git config -- add remote.origem.fetch +refs / heads / : refs / remotes/origem/

 0
Author: pavan, 2018-05-09 14:10:02