git fatal: branch ‘master‘ does not exist


問題重現
1. 先在一個空文件夾里右擊,然后點擊 git bash here

 

 


2. 輸入下面命令

git init

 

 

 

3、我們假設要關聯一個遠程分支 https://gitee.com/kaimo313/webgl-demo.git
執行下面命令

git remote add origin https://gitee.com/kaimo313/webgl-demo.git

 

 


4、再執行拉取代碼命令

git pull

  


不出意外就會報下面的提示

 

 

 

5、輸入提示的命令

git branch --set-upstream-to=origin/master master

  

然后就會提示出來這個問題 

fatal: branch 'master' does not exist

  

 

 

原因
出現這個問題原因就是本地沒有 master 分支導致的。

輸入 git branch -a。發現只有遠程分支。

 

 

 

解決
解決方式就是:輸入 git checkout master。

 

 

 

 

出現 Already on 'master' ,Branch 'master' set up to track remote branch 'master' from 'origin'.,說明已經切換到 master 上。

再次輸入 git branch -a。發現已經有本地分支

 

 

 

在用 git branch -avvv 查看

【a:查看所有分支】
【v:每個分支的最后一個提交(commit)】
【vv:本地分支與遠程分支的關聯關系】

 


免責聲明!

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



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