How can I switch to another branch in git?

后端 未结 9 656
难免孤独
难免孤独 2021-01-29 17:38

Which one of these lines is correct?

git checkout \'another_branch\'

Or

git checkout origin \'another_branch\'
         


        
相关标签:
9条回答
  • 2021-01-29 18:28

    [git checkout "branch_name"]

    is another way to say:

    [git checkout -b branch_name origin/branch_name]

    in case "branch_name" exists only remotely.

    [git checkout -b branch_name origin/branch_name] is useful in case you have multiple remotes.

    Regarding [git checkout origin 'another_branch'] I'm not sure this is possible, AFAK you can do this using "fetch" command -- [git fetch origin 'another_branch']

    0 讨论(0)
  • 2021-01-29 18:34

    With Git 2.23 onwards, one can use git switch <branch name> to switch branches.

    0 讨论(0)
  • 2021-01-29 18:34

    If you want the branch to track the remote branch, which is very important if you're going to commit changes to the branch and pull changes etc, you need to add a -t for the actual checkout like so: git checkout -t branchname

    0 讨论(0)
提交回复
热议问题