開發與維運

git push報錯:The current branch master has no upstream branch

問題

進行git push操作時報錯:fatal: The current branch master has no upstream branch.

在這裡插入圖片描述

原因:沒有將本地的分支與遠程倉庫的分支進行關聯
通過git branch查看本地分支只有master

在這裡插入圖片描述

通過git branch -a查看遠程分支,有masterremotes/origin/master兩個

在這裡插入圖片描述

這時由於遠程倉庫太多,且分支較多。在默認情況下,git push時一般會上傳到origin下的master分支上,然而當repositorybranch過多,而又沒有設置關聯時,git就會產生疑問,因為它無法判斷你的push目標

解決

方式一

使用git push --set-upstream origin master命令

方式二

使用git push -u origin master命令

Leave a Reply

Your email address will not be published. Required fields are marked *