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

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'

当前回答

如果您在Windows上使用GitBash,请尝试重新启动它。它对我有用!

其他回答

在删除本地计算机上的所有文件后,我也出现了类似的错误,我必须清理存储库中的所有文件。

我的错误消息如下:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

通过执行以下命令解决了问题:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

我今天也遇到了同样的问题。我创建了一个新的repo并将其克隆到我的机器上。我提交了我的代码并尝试推送它。我也收到了同样的错误。我观察到这是因为我在使用:

git推送原始主机

我在这里做错的是,我假设我的默认分支是master,而GitHub上的新默认分支是main。我推送时使用:

git推送原点主

而且效果很好。

我的解决方案只适用于最近面临这个问题的较新的repo或用户,因为GitHub正在取代主要的over-master术语。因此,如果您收到此错误,请确保检查要推送到的分支以及GitHub上的分支名称。

如果在分离HEAD模式下工作时出现此错误,可以执行以下操作:

git push origin HEAD:remote-branch-name

另请参见:从分离的头部推动Git

如果您所在的本地分支与远程分支不同,可以执行以下操作:

git push origin local-branch-name:remote-branch-name

我忘记在提交之后和推送之前执行“git pull-origin master”,这导致了同样的问题:“在git中推送提交时,src-refspec-master不匹配”。

因此,您应该做到:

1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master

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

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