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

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 init
git add .
git commit -m <Your commit message>
git remote add origin "your repository link here"
git push -u origin master

其他回答

截至2020年10月1日,GitHub正在将主分支的名称更改为main。这就是导致问题的原因。当有人键入git push origin master时,他们会看到此错误错误:src refspec master与任何错误都不匹配:未能将某些ref推送到'https://github.com/username/reponame.git'

这可以通过使用git push origin main来解决。希望这有帮助。我花了很长时间才弄明白为什么我不能将我的承诺提交给主分支。

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

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

git分支使用-mv标志重命名分支:git分支-mv源主机

在这个git分支之后应该显示master

要检查当前状态,请使用gitstatus。

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master