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

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'

当前回答

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

我的错误消息如下:

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.

其他回答

如果你的分支机构名称中有一个拼写错误,因此你试图推送一些不存在的东西,这也可能发生!哈

在我的例子中,我实际上创建了一个名称不正确的分支(显然是偶然的),它被称为fetrare/<something>,并试图推送feature/<some东西>

大脑会将单词作为一个单元来阅读,因此有时两个单词看起来相同,但实际上并非如此!哈

只需确保分支机构名称中没有拼写错误!(或者更好地说,检查您要推送的分支是否与您在本地定义的分支相匹配,特别是如果您正在手动推送新创建的分支git推送源特性/<newBranch>)

git分支使用-mv标志重命名分支:git分支-mv源主机

在这个git分支之后应该显示master

更新以前的答案。

此外,别忘了github已经将“Master”更改为“Main”,因此请确保您通过以下方式进行推送:

git push origin main

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

然后错误消失。

我也遇到了同样的问题,并且发现我没有提交任何文件,所以当我再次尝试提交时,我收到了以下错误消息:

*** Please tell me who you are.

Run

 git config --global user.email "you@example.com"
 git config --global user.name "Your Name"

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

然后我所做的就是在全球范围内添加我的电子邮件和姓名,然后再次提交:

git commit -m 'Initial commit'

然后按下

git push -u origin master