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

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的错误:

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

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master

其他回答

对我来说,以下操作可以移动未跟踪的文件:

git add --all

接下来,我遵循了类似的步骤

 git commit -m "First commit"

然后

git remote add origin git@github.....

最后但并非最不重要的是:

git push -u origin master

当您执行此操作时,Windows安全将弹出窗口,询问您的用户名和密码。

如果在分离HEAD模式下工作时出现此错误,可以执行以下操作:

git push origin HEAD:remote-branch-name

另请参见:从分离的头部推动Git

如果您所在的本地分支与远程分支不同,可以执行以下操作:

git push origin local-branch-name:remote-branch-name

来自Git的错误:

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

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master

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

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

补充

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

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

我的错误消息如下:

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.