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

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'

当前回答

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

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

git push origin main

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

其他回答

确保分支名称中没有不可见的拼写错误:

git branch

输出:

master
* <U+0096>your_branch_name

有一个不可见的<U+0096>字符,可能是通过粘贴分支名称到达的。

将当前分支重命名为正确的值,然后重试推送:

git branch -m your_branch_name

我的分支名为bugfix-22112022/5v8ST5Q6/181 kontaktformular eingabe nach anmeldung-übernehmen,<--是的,它有一个逗号,我认为逗号不是它的一部分,并在尝试推送时删除了它。。。

我重命名了我的分支:

git branch -m bugfix-22112022/5v8ST5Q6/181-kontaktformular-eingabe-nach-anmeldung-übernehmen

2020年:

如果30个以上的答案都无效,您可能需要运行git push origin main(在编写此答案时,master已重命名为main)。

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

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

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