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

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 branch
* version-x  # you are in this branch
  version-y

$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'

其他回答

如果要在原点远程创建新分支,则需要首先在本地创建相同的分支:

$ git clone -b new-branch
$ git push origin new-branch

在我的例子中,错误发生在我将更改推送到仅在本地拥有的分支时。远程分支不存在同名。我使用以下命令解决了该错误:

git push --set-upstream origin "your-branch-name"

Github将默认分支名称从master更改为main。因此,如果您最近创建了回购,请尝试推送主分支

git push origin main

Github文章

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

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

简短回答:此错误意味着您要在远程推送的分支不存在!

在我的案例中,从2020年10月开始,此后创建的回购协议拥有主分支,而不是之前的主分支。所以我要做的就是:

git push -u origin main 

如果设置了上游,则可以跳过-u标志(就像您已经克隆了它一样)

答对 了这对我有用!希望这有帮助!编码愉快!