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

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 checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

其他回答

git push-u原始主机

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

这是由于存储库仍然是空的。存储库中没有提交,因此没有主分支可以推送到服务器。

这对我有用

决议

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

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

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

当您在一个特定的分支中并尝试推送另一个尚不存在的分支时,也会发生这种情况,例如:

$ git branch
* version-x  # you are in this branch
  version-y

$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'

我也收到了这个问题,但这是因为我在推送之前意外关闭了服务器。这也会导致同样的错误。

我想是因为你推了一个无效的分支。

通常,因为存储库没有公共的主分支(可能是开发分支)。您可以使用

git branch

查看分支。