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

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'

当前回答

我也面临同样的问题。但我注意到,发生此错误时,我的目录是空的。当我创建了一个示例文件并再次推送时,它起了作用。因此,在推送之前,请确保您的文件夹不是空的!!

其他回答

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

来自Git的错误:

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

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master

当我没有提到起源的主分支时,这发生在我身上。因此,您可以尝试以下操作:

git pull origin master

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

git push -u origin master

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

要修复它,请重新初始化并遵循正确的代码序列:

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