我使用以下内容克隆存储库:

git clone ssh://xxxxx/xx.git 

但在我更改一些文件并添加和提交它们之后,我想将它们推送到服务器:

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

但我得到的错误是:

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

当前回答

截至2020年10月1日,GitHub正在将主分支的名称更改为main。这就是导致问题的原因。当有人键入git push origin master时,他们会看到此错误错误:src refspec master与任何错误都不匹配:未能将某些ref推送到'https://github.com/username/reponame.git'

这可以通过使用git push origin main来解决。希望这有帮助。我花了很长时间才弄明白为什么我不能将我的承诺提交给主分支。

其他回答

我也遇到了同样的问题,并且发现我没有提交任何文件,所以当我再次尝试提交时,我收到了以下错误消息:

*** Please tell me who you are.

Run

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

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

然后我所做的就是在全球范围内添加我的电子邮件和姓名,然后再次提交:

git commit -m 'Initial commit'

然后按下

git push -u origin master

我面临这个问题,因为我已经创建了一个分支,我必须使用该分支,然后通过使用该分支解决了问题。

git推送源分支名称

此问题的另一个可能原因是您拼写错误了分支名称。因此,如果你做了我所做的,那么问题将通过纠正来解决:

git push origin mater

to

git push origin master

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

Github将默认分支名称从master更改为main。因此,如果您最近创建了回购,请尝试推送主分支

git push origin main

Github文章