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

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 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'

其他回答

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

我也有同样的问题。我通过以下步骤做到了这一点:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master

我遇到了这个问题,根本原因是我在创建新项目时遵循了GitLab中提到的步骤

cd现有文件夹gitinit--初始分支=maingit远程添加来源你的回购git添加。gitcommit-m“初始提交”git push-u origin main

没有在推送之前在本地目录中添加任何文件,因此它不被视为提交,因为没有什么要提交的(尽管您运行git add.和git commit-m“initial commit”命令)。确保在本地目录添加一些文件,那么只有git会将其视为提交。然后推送解决了错误

面临的问题

当我在GitHub上创建一个新的存储库并将其与我的客户端计算机上的react应用程序链接时,我也遇到了同样的问题。

我使用了以下步骤:

出现问题之前使用的命令

git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

我的错误

但正如你所见,我的错误是没有使用gitadd。命令我犯了这个错误,因为我已经有了README.md文件,而GitHub在创建存储库时会指导我们使用基本命令。

我的解决方案

我的解决方案是使用gitadd。gitinit命令之后。

按照相同的顺序使用以下命令集来解决问题:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

在我Git只添加了一个目录之后,我发现这发生在一个全新的存储库中。

一旦我添加了一个文件(例如README),Git推送就非常成功。