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

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 add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

其他回答

在我的例子中,错误发生在我将更改推送到仅在本地拥有的分支时。远程分支不存在同名。我使用以下命令解决了该错误:

git push --set-upstream origin "your-branch-name"

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

$ 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 push-u origin master,但我得到了错误。

一旦我cd到当前目录,执行gitpush-uorigin-master,一切都很好。

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

我的工作流程:

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

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

本月的一个原因可能是:github已将默认的“master”分支重命名为“main”分支。因此,请改用git push origin main。