在Git中推送提交時出現消息「 src refspec master不匹配」

我用如下方法克隆個人存儲庫: php

git clone ssh://xxxxx/xx.git

可是,在我更改了一些文件並addcommit它們以後,我想將它們推送到服務器: git

git add xxx.php
git commit -m "TEST"
git push origin master

可是我獲得的錯誤是: github

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

#1樓

當您在特定分支中並嘗試推入尚不存在的另外一個分支時,也會發生這種狀況,例如: 服務器

$ git branch
* version-x  # you are in this branch
  version-y

$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'

#2樓

若是是第一次使用它,則須要配置Git安裝,它具備: ssh

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

#3樓

缺乏或跳過git add .git commit可能致使此錯誤: ide

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

要修復此問題,請從新初始化並遵循正確的順序: this

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master

#4樓

  1. 個人更改已經提交
  2. 強制推送仍然給了我一樣的錯誤。

因此我嘗試了Vi的解決方案spa

git push origin HEAD:<remoteBranch>

這對我有用。 code


#5樓

若是您要推送的分支名稱中有錯字,也會發生這種狀況。 rem

相關文章
相關標籤/搜索