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

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 pull--重新基数https://github.com/yours主人git添加。gitcommit-m'提交消息'git推送原始主机

其他回答

我为一个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

当您试图将空回购推送到git服务器时,会发生此错误。这可以通过初始化README.md文件来缓解:

cat > README.md

然后键入一些内容,然后输入一个回车键,然后按CTRL+D保存。然后是通常的提交步骤:

git add .
git commit -m "Initial commit"
git push origin master

我已经创建了一个提交。确保您正在向正确的分支推进。

我键入的是git push origin master,但当我键入git branch时,我是在v1分支上,所以我必须键入git pushorigin v1。

对我来说,我必须确保公钥在服务器(附加在~/.ssh/authorized_keys中)和GitHub/Bitbucket(添加到GitHub或Bitbucket上的ssh密钥中)中正确配置-它们需要匹配。然后:

git add --all :/
git commit -am 'message'
git push -u origin master

我收到这个错误,因为我的本地分支名称与我试图使用git push origin创建的新远程分支不匹配。