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

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'

当前回答

我遇到了这个问题,根本原因是我在创建新项目时遵循了GitLab中提到的步骤

cd现有文件夹gitinit--初始分支=maingit远程添加来源你的回购git添加。gitcommit-m“初始提交”git push-u origin main

没有在推送之前在本地目录中添加任何文件,因此它不被视为提交,因为没有什么要提交的(尽管您运行git add.和git commit-m“initial commit”命令)。确保在本地目录添加一些文件,那么只有git会将其视为提交。然后推送解决了错误

其他回答

我也面临同样的问题。在我的案例中,我在添加之前犯了错误。按顺序执行这些步骤后,我得到了它。

此外,请确保提供正确的分支名称。

git init
git add .
git commit -m <Your commit message>
git remote add origin "your repository link here"
git push -u origin master

我错过跑步时也遇到了同样的问题:

git add .

(必须至少有一个文件,否则会再次出现错误。)

缺少或正在跳过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

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

我的错误消息如下:

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.
git add .

这就是你所需要的。该代码跟踪目录中所有未跟踪的文件。