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

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告诉我:

*** Please tell me who you are.

Run

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

或设置帐户的默认身份。

Omit --global to set the identity only in this repository.

然后错误消失。

其他回答

在我的例子中,出现在Windows上的问题似乎与我们在分支名称中添加前缀类似feature\有关。我们试图创建并推送一个具有这样前缀的分支(例如,feature\branch),但已经有一个不同的分支,其前缀为feature\(例如,feature\otherbranch)。这意味着在Windows上,新分支被放置在相同的refs\heads\Feature文件夹中。Git可能区分大小写,但Windows文件系统不区分大小写。一旦我们签出了名为Feature\branch的本地分支,它就起到了作用。

2020年:

如果30个以上的答案都无效,您可能需要运行git push origin main(在编写此答案时,master已重命名为main)。

我错过跑步时也遇到了同样的问题:

git add .

(必须至少有一个文件,否则会再次出现错误。)

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*
git push -u origin master
error: src refspec master does not match any.

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

git commit -m "initial commit"

git push origin master

已成功推送到主机。