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

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'

当前回答

对于Windows上Cmder中Bash的用户,请确保在新的主目录中创建一个新的.ssh文件夹。

转到主目录cd~。生成ssh密钥ssh-keygen。保持所有输入为空(保持按回车键)将id_rsa.pub文件复制到Github>设置>SSH密钥

其他回答

再次检查您是否推送了正确的分支名称。我遇到了同样的错误,在查看git show ref之后,我能够看到我输入了错误,因此,没有ref。

来自Git的错误:

错误:src-refspec-master与任何不匹配。

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master

也许你只需要承诺。当我这样做的时候,我遇到了:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .

哎呀!从未承诺!

git push -u origin master
error: src refspec master does not match any.

我所要做的就是:

git commit -m "initial commit"
git push origin main

成功

我遇到了同样的问题,我使用了--允许空:

$ git commit -m "initial commit" --allow-empty
...
$ git push
...

补充

这个问题的一个主要原因是,在克隆新的存储库时,一些Git服务器(如BitBucket)没有初始化其主分支。

我在尝试将内容推送到GitHub上的新存储库时遇到了这个错误。我在本地创建了Git存储库,并且使用Web GUI(包括一个LICENSE文件)在GitHub上创建了存储库。

在我将LICENSE文件从原本空的GitHub存储库拉到本地存储库后,问题消失了。之后,我可以毫无问题地推进。