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

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,则需要配置Git安装,包括:

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

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

其他回答

我面临着同样的问题,并尝试了这里的大多数答案,但问题是因为最近Github重命名的变化。

GitHub正在逐步将存储库的默认分支从master重命名为main。

https://github.com/github/renaming

您的新命令将是:

git push origin main

而不是:

git push origin master

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

git push origin HEAD:remote-branch-name

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

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

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

我忘了承诺,然后跑去做这个。只需提交

我遇到了同样的困难。。解决方案是将代码推送给回购,就好像它是一个现有项目,而不是一个正在初始化的全新项目。

git remote add origin https://github.com/Name/reponame.git
git branch -M main
git push -u origin main

再次检查您是否推送了正确的分支名称。我遇到了同样的错误,在查看git show ref之后,我能够看到我输入了错误,因此,没有ref。