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

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'

当前回答

在删除本地计算机上的所有文件后,我也出现了类似的错误,我必须清理存储库中的所有文件。

我的错误消息如下:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

通过执行以下命令解决了问题:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

其他回答

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

如果您在Windows上使用GitBash,请尝试重新启动它。它对我有用!

只需添加初始提交。遵循以下步骤:

git添加。gitcommit-m“初始提交”git推送原始主机

这对我有用。

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

为此,您需要按如下方式输入提交消息,然后推送代码:

git commit -m "initial commit"

git push origin master

已成功推送到主机。

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*