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

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'

当前回答

我在尝试将内容推送到GitHub上的新存储库时遇到了这个错误。我在本地创建了Git存储库,并且使用Web GUI(包括一个LICENSE文件)在GitHub上创建了存储库。

在我将LICENSE文件从原本空的GitHub存储库拉到本地存储库后,问题消失了。之后,我可以毫无问题地推进。

其他回答

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

要检查当前状态,请使用gitstatus。

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

最近遇到了这个问题,我所做的是使用检查show ref,git显示参考并检查

参考/主管/主管

出席。

它是存在的,但它仍然对我不起作用。

在我写作的时候

 git push origin main

后来我用git推送原始主机

这对我来说非常好。

我面临着类似的错误。错误是由此命令引起的

git push -u origin master

随后的命令对我有效

从以下命令开始

git init
git add .
git commit -m "second commit"

所以在推送它之前,运行这些命令,看看我们的本地存储库连接到Github上的哪个远程存储库,以及您所在的分支。

git remote
git branch

远程-->原点

分支-->主

git push -u remote branch

或更具体地:

git push -u origin main

2020年底,GitHub将其主分支更改为主分支。

我注意到GitHub创建了一个新的分支master,当我使用git push-u origin master时,这不是主分支:

现在,当我尝试使用gitpush-uorigin-main来直接推送到main分支时,会出现以下错误:

我面临这个错误:

src refspec main does not match any
error: failed to push some refs to 'https://github.com/<my_project_name>.git

在我第一次提交到main之后,我使用以下步骤修复了它。在以下代码中更改GitHub的URL:

git branch -M main
git remote add origin https://github.com/Sidrah-Madiha/<my_project_url>.git
git push -u origin main