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

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'

当前回答

更新以前的答案。

此外,别忘了github已经将“Master”更改为“Main”,因此请确保您通过以下方式进行推送:

git push origin main

其他回答

我也犯了类似的错误。但Git告诉我:

*** Please tell me who you are.

Run

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

或设置帐户的默认身份。

Omit --global to set the identity only in this repository.

然后错误消失。

我面临这个问题,因为我已经创建了一个分支,我必须使用该分支,然后通过使用该分支解决了问题。

git推送源分支名称

为了避免在2021及以后出现此错误,请在使用git init之前使用此命令

git-config--全局init.defaultBranch main这告诉您的git始终使用main作为默认分支名称,而不是master

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

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

这个问题主要有两种可能性。让我们逐一考虑一下。

可能是错误,主分支甚至不存在。在我的例子中,它被命名为main,而不是master。在这种情况下,您需要用main替换master。您甚至还没有提交更改。如果是这种情况,请转到-->

git添加。gitcommit-m“初始提交”git推送原点<branch>

那么它应该会起作用。

尝试一下,会很好。:)