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

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 checkout master
git commit -a -m "your comment"
git push origin master

我错过跑步时也遇到了同样的问题:

git add .

(必须至少有一个文件,否则会再次出现错误。)

我也遇到了同样的问题,并且发现我没有提交任何文件,所以当我再次尝试提交时,我收到了以下错误消息:

*** Please tell me who you are.

Run

 git config --global user.email "you@example.com"
 git config --global user.name "Your Name"

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

然后我所做的就是在全球范围内添加我的电子邮件和姓名,然后再次提交:

git commit -m 'Initial commit'

然后按下

git push -u origin master

我想是因为你推了一个无效的分支。

通常,因为存储库没有公共的主分支(可能是开发分支)。您可以使用

git branch

查看分支。

这只是意味着你忘了做初始提交,试试

git add .
git commit -m 'initial commit'
git push origin master