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

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'

当前回答

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

git推送原始主机

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

git推送原点主

而且效果很好。

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

其他回答

再次检查您是否推送了正确的分支名称。我遇到了同样的错误,在查看git show ref之后,我能够看到我输入了错误,因此,没有ref。

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

2021,GitHub将默认分支名称更改为main。以前它是主人。

我之所以痛苦,是因为我试图向不存在的主服务器推送,而远程的分支是主服务器。确保您使用的分支名称正确。

下面的命令对我有效

git push origin main

也许你只需要承诺。当我这样做的时候,我遇到了:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .

哎呀!从未承诺!

git push -u origin master
error: src refspec master does not match any.

我所要做的就是:

git commit -m "initial commit"
git push origin main

成功

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

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