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

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 add .

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

其他回答

此问题的另一个可能原因是您拼写错误了分支名称。因此,如果你做了我所做的,那么问题将通过纠正来解决:

git push origin mater

to

git push 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 branch -m new_shorter_branch_name

解决了问题。