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

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'

当前回答

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

其他回答

我也面临同样的问题。但我注意到,发生此错误时,我的目录是空的。当我创建了一个示例文件并再次推送时,它起了作用。因此,在推送之前,请确保您的文件夹不是空的!!

我遇到了这个错误,因为我使用了字符“&”,所以分支的名称有问题。我只是跳过了“^&”,它起了作用。

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

然后错误消失。

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

尝试git show ref,看看你有哪些ref。有裁判/主管/主管吗?

由于最近的“在GitHub中用main替换master”操作,您可能会注意到有一个refs/heads/main。因此,以下命令可能会从gitpushoriginHEAD:master更改为gitpushorigin HEAD:main

您可以尝试git push origin HEAD:master作为一个更独立于本地引用的解决方案。这明确表示您希望将本地ref HEAD推送到远程ref master(请参阅git push-refspec文档)。