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 <遠程主機名> <分支名> 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM