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

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'

当前回答

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

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

其他回答

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

git push origin main

Github文章

尝试git show ref,看看你有哪些ref。有裁判/主管/主管吗?

由于最近的“在GitHub中用main替换master”操作,您可能会注意到有一个refs/heads/main。因此,以下命令可能会从gitpushoriginHEAD:master更改为gitpushorigin HEAD:main

您可以尝试git push origin HEAD:master作为一个更独立于本地引用的解决方案。这明确表示您希望将本地ref HEAD推送到远程ref master(请参阅git push-refspec文档)。

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

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

对我来说,我必须确保公钥在服务器(附加在~/.ssh/authorized_keys中)和GitHub/Bitbucket(添加到GitHub或Bitbucket上的ssh密钥中)中正确配置-它们需要匹配。然后:

git add --all :/
git commit -am 'message'
git push -u origin master

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

*** 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