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

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 push origin HEAD

其他回答

在您从外部存储库(GitHub)中检出代码,并希望将其导入个人/内部系统的场景中,此命令非常有用:

git push --all origin

这会将所有本地分支推到远程,而无需检查ref,也无需坚持提交。

要检查当前状态,请使用gitstatus。

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

也许你只需要承诺。当我这样做的时候,我遇到了:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .

哎呀!从未承诺!

git push -u origin master
error: src refspec master does not match any.

我所要做的就是:

git commit -m "initial commit"
git push origin main

成功

我为一个GitHub存储库做了贡献,所以我分叉了这个项目,克隆了它,创建了自己的分支,进行了一些提交,并尝试推送。

此时,我发现我克隆的不是我的fork,而是原始的项目存储库(我没有权限将其推送到)。

所以我更改了.git/config以将原点指向我的存储库。

此时,当我尝试推送时,我收到了错误消息:src-refspec my_awesome_branch不匹配。

我所要做的就是触摸任何文件并提交它(就像你在这个答案中看到的一样):

git touch README
git commit -m "fixing error in my git repo"

然后:

git checkout master
git pull origin master
git push origin master # This will tell my remote repository about my new branch
git checkout my_awesome_branch
git push origin my_awesome_branch # Now it will work

当您添加了文件,忘记提交和推送时,就会发生这种情况。所以提交文件,然后推送。