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

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

其他回答

只需添加初始提交。遵循以下步骤:

git添加。gitcommit-m“初始提交”git推送原始主机

这对我有用。

这只是意味着你忘了做初始提交,试试

git add .
git commit -m 'initial commit'
git push origin master

缺少或正在跳过git add。或gitcommit可能会导致此错误:

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

要修复此问题,请重新初始化并遵循正确的顺序:

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master

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

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

下面的命令对我有效

git push origin main

同时检查是否更改了分支名称

对我来说,我已经将分支名称从添加状态条件更改为添加状态条件,但没有注意到末尾缺少的s。正确重命名了分支,git推送原点添加了状态条件-f。

这对我有用。