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

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

其他回答

更新以前的答案。

此外,别忘了github已经将“Master”更改为“Main”,因此请确保您通过以下方式进行推送:

git push origin main
git add .

这就是你所需要的。该代码跟踪目录中所有未跟踪的文件。

添加空目录时遇到此问题。Git不允许推送空目录。这里有一个简单的解决方案。

在要推送到远程的目录中创建文件.gitkeep,并从命令行提交“空”目录:

touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"

如果你在第一次推之前忘记承诺,就会发生这种情况。只需运行:

git commit -m "first commit"

只有提交解决了此错误:

git commit -m "first commit"