zoukankan      html  css  js  c++  java
  • Git切换远程分支

         1. 切换git远程分支,使用命令:git checkout -b 分支名称。 

    •   注意:切换远程分支一定要带伤-b 参数,只有切换本地分支的时候才不需要 -b参数,-b 的意思是 base,以当前分支为 base,新建一个名叫xxx 的分支  。如果使用 "git branch 远程分支名" 命令切换到远程服务器分支上,

               则会导致如下错误提示:

    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b <new-branch-name>

              这时候再使用git branch 命令查看本地分支,就会发现当前分支是在一个 叫“(HEAD detached at 远程分支名)”上。detached是游离的意思,表名当前分支是在游离状态。    

         2. 远程服务器新建了分支,本地无法checkout ,或者本地看不到,使用命令: git branch -r 可以查看远程分支。

              如果这时候直接使用 git checkout -b xxxx 去切换到远程分支,是会报如下错误的
            

      error: pathspec 'branch170628_foo' did not match any file(s) known to git   

          请使用命令:git fetch 更新remote索引

          取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名,例:$ git fetch <远程主机名> <分支名> 

  • 相关阅读:
    【PAT】 B1006 换个格式输出整数
    【PAT】B1014 福尔摩斯的约会
    【PAT】B1005 继续(3n+1)猜想
    【PAT】B1004 成绩排名
    【PAT】B1003 我要通过!
    【PAT】B1002 写出这个数
    【PAT】B1001 害死人不偿命的(3n+1)猜想
    【PAT】A1001A+B Format
    【PAT】B1027 打印沙漏(20 分)
    【PAT】B1032 挖掘机技术哪家强(20 分)
  • 原文地址:https://www.cnblogs.com/xuzimian/p/10748522.html
Copyright © 2011-2022 走看看