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

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 commit -m "initial commit" --allow-empty
...
$ git push
...

补充

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

其他回答

我也犯了同样的错误;我的问题就是这样解决的:

git config --global user.email "YOUR EMAIL"
git config --global user.name "YOUR NAME"

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

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

如果您是第一次使用Git,则需要配置Git安装,包括:

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

git config --global user.name "Your Name"

我也有同样的问题。我通过以下步骤做到了这一点:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master

缺少或正在跳过git add。或gitcommit可能会导致此错误:

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

要修复此问题,请重新初始化并遵循正确的顺序:

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master