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

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 push origin创建的新远程分支不匹配。

其他回答

GitHub更新01.10.20后,您应该使用main而不是master。

这样做。。。

在GitHub上创建存储库删除本地目录中现有的.git文件转到本地项目目录并键入gitinitgit添加。gitcommit-m“我的第一次通信”现在检查您的分支机构名称,它将在您的本地项目中处于主导地位gitremoteadd origin<github存储库中的远程存储库URL>,然后键入gitremote-vgit push-f原始主机现在检查github存储库,您将看到两个分支1。主要2。主人在本地存储库中创建新分支,分支名称将为maingit结帐总管git合并主机git拉起点总管git push-f origin main

注意:从2010年10月1日起,github决定使用main而不是master分支使用默认分支名称

要修复它,请重新初始化并遵循正确的代码序列:

git init
git add .
git commit -m 'message'
git push -u origin master

我今天也遇到了同样的问题。我创建了一个新的repo并将其克隆到我的机器上。我提交了我的代码并尝试推送它。我也收到了同样的错误。我观察到这是因为我在使用:

git推送原始主机

我在这里做错的是,我假设我的默认分支是master,而GitHub上的新默认分支是main。我推送时使用:

git推送原点主

而且效果很好。

我的解决方案只适用于最近面临这个问题的较新的repo或用户,因为GitHub正在取代主要的over-master术语。因此,如果您收到此错误,请确保检查要推送到的分支以及GitHub上的分支名称。

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

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
git push -u origin master
error: src refspec master does not match any.

为此,您需要按如下方式输入提交消息,然后推送代码:

git commit -m "initial commit"

git push origin master

已成功推送到主机。