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

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'

当前回答

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

其他回答

只需添加初始提交。遵循以下步骤:

git添加。gitcommit-m“初始提交”git推送原始主机

这对我有用。

确保分支名称中没有不可见的拼写错误:

git branch

输出:

master
* <U+0096>your_branch_name

有一个不可见的<U+0096>字符,可能是通过粘贴分支名称到达的。

将当前分支重命名为正确的值,然后重试推送:

git branch -m your_branch_name

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

由于多种原因,您可能会遇到此问题。

1.暂存文件的待定提交

如果您通过运行gitadd命令(即gitadd.)添加了更改,并且从未提交过这些文件,则在之后,尝试将分支推入远程存储库。在这种情况下,您将面临src-refspec-master不匹配的错误。

2.本地分支机构名称无效

如果您在分支的名称中键入了错误(即mster而不是master),则会导致此错误。表示您尝试推入的分支不在本地存储库中。

在我的例子中,fastlane match nuke开发(它从git凭证存储和开发者门户中删除开发证书和配置文件)试图推送master,但我们没有master。由于我们有两个不同的团队,我们也有两个分支机构。解决问题的方法是打电话告诉match正确的分支:

fastlane match --git_branch <your_branch> nuke development