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

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 init
git add .
git commit -m "message"
prompt me to enter email and user name
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

输入上述详细信息后,文件将提交并成功推送:

git push

其他回答

我也收到了这个问题,但这是因为我在推送之前意外关闭了服务器。这也会导致同样的错误。

我收到这个错误,因为我的本地分支名称与我试图使用git push origin创建的新远程分支不匹配。

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

我的错误消息如下:

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 pull origin master

这将在本地存储库中创建对源的主分支的引用。然后,您可以将本地存储库推送到源位置。

git push -u origin master