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

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'

当前回答

我犯了这个错误,

错误:src-refspec-master与任何不匹配。

当我试图将提交推送到GitHub时,发生了变化(在GitHub)。

git push -u origin branch-name - helped me to get my local files up to date

其他回答

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

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

下面的命令对我有效

git push origin main

我想这可能会对某人有所帮助。我今天做出了我的第一次重大承诺。我试了很多指南,但总是出错。

首先:将文件cd到目录中初始化git:gitinit提交文件:gitcommit要在有任何模糊的bash命令时强制提交,请单击I插入提交消息要继续:单击Esc

要发送到GitHub存储库,请首先确保已添加用户名和电子邮件:

git config --global user.name 'Your name'
git config --global user.email 'name@mail.com'

继续:

git remote add origin https://github repo url

要推送到存储库:

git push -u origin 'https://github.repo url'

它将提交加载到存储库中。

完成!!!

简短回答:此错误意味着您要在远程推送的分支不存在!

在我的案例中,从2020年10月开始,此后创建的回购协议拥有主分支,而不是之前的主分支。所以我要做的就是:

git push -u origin main 

如果设置了上游,则可以跳过-u标志(就像您已经克隆了它一样)

答对 了这对我有用!希望这有帮助!编码愉快!

本月的一个原因可能是:github已将默认的“master”分支重命名为“main”分支。因此,请改用git push origin main。

2022年2月更新:

如果您的分支是“main”:

运行以下命令:

git push origin main

如果您的分支是“master”:

运行以下命令:

git push origin master