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

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'

当前回答

对于存储库WIKI,我也遇到了此错误。

git show-branch

如果显示master,则

git push -u origin master

其他回答

由于多种原因,您可能会遇到此问题。

1.暂存文件的待定提交

如果您通过运行gitadd命令(即gitadd.)添加了更改,并且从未提交过这些文件,则在之后,尝试将分支推入远程存储库。在这种情况下,您将面临src-refspec-master不匹配的错误。

2.本地分支机构名称无效

如果您在分支的名称中键入了错误(即mster而不是master),则会导致此错误。表示您尝试推入的分支不在本地存储库中。

我也犯了类似的错误。但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.

然后错误消失。

权限问题?解决方案:分叉

我收到这个错误是因为我没有对存储库的推送权限,所以我不得不分叉它,然后我在分叉的存储库上再次执行了pull、commit和push命令。

这对我有用:

只需签出主分支:

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

或者使用——强制改变。

git push origin master --force

我也有同样的问题。我通过以下步骤做到了这一点:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master