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

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

更新答案:确保所有更改都已提交。

然后键入:gitpush在这之前,请确保创建一个个人访问令牌,GitHub现在使用这个。然后键入您的GitHub用户名(键入gitpush后),然后将您的个人访问令牌粘贴到密码输入中。

所有这些之后,您应该可以在GitHub中看到您的更改!

对于GitLab用户,GitLab的更新版本现在将有一个“main”分支作为默认分支。

因此,您可以尝试以下操作:

git push origin main

参考:GitLab新Git默认分支名称为main

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

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

2022年2月更新:

如果您的分支是“main”:

运行以下命令:

git push origin main

如果您的分支是“master”:

运行以下命令:

git push origin master