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

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'

当前回答

权限问题?解决方案:分叉

我收到这个错误是因为我没有对存储库的推送权限,所以我不得不分叉它,然后我在分叉的存储库上再次执行了pull、commit和push命令。

其他回答

如果在分离HEAD模式下工作时出现此错误,可以执行以下操作:

git push origin HEAD:remote-branch-name

另请参见:从分离的头部推动Git

如果您所在的本地分支与远程分支不同,可以执行以下操作:

git push origin local-branch-name:remote-branch-name

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

我以前也遇到过同样的问题。问题出在我当地分行的名字上。它与我试图推动的不同。将分支名称更正为目标名称后,我能够推动更改。

记住本地分支和目标分支应该相同。

如果要在原点远程创建新分支,则需要首先在本地创建相同的分支:

$ git clone -b new-branch
$ git push origin new-branch

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