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

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推送原始主机

其他回答

当我收到src-refspec错误时,上述解决方案都不适用。

我的工作流程:

推送到远程分支(相同的本地分支名称)删除了远程分支改变了一些东西再次推送到相同的远程分支名称(相同的本地分支名称)获取src-refspec错误。

我通过简单地创建一个新分支并再次推送来修复错误。(奇怪的是,我不能简单地重命名分支,这给我带来了致命的后果:分支重命名失败。)

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

添加空目录时遇到此问题。Git不允许推送空目录。这里有一个简单的解决方案。

在要推送到远程的目录中创建文件.gitkeep,并从命令行提交“空”目录:

touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"

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

$ 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 init
git add .
git commit -m 'message'
git push -u origin master