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

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'

当前回答

对我来说,这似乎是因为我已经完成了提交过程,所以我在尝试再次提交后得到了这个结果。

Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

因为我看到路径是origin/main,所以我将其推到main而不是master,并且它起了作用。

注意:检查以确定主分支是主分支还是主分支。

截至2022年。

其他回答

确保你正在推到正确的分支,或者有任何拼写错误。使用此命令检查当前工作分支的名称git显示分支

这对我有用:

只需签出主分支:

git checkout -b master
git add .
git push origin master

或者使用——强制改变。

git push origin master --force

我也收到了这个问题,但这是因为我在推送之前意外关闭了服务器。这也会导致同样的错误。

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

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

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