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

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 master,但当我键入git branch时,我是在v1分支上,所以我必须键入git pushorigin v1。

其他回答

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

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

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

同时检查是否更改了分支名称

对我来说,我已经将分支名称从添加状态条件更改为添加状态条件,但没有注意到末尾缺少的s。正确重命名了分支,git推送原点添加了状态条件-f。

这对我有用。

我的问题是“主”分支尚未在本地创建。

快速

git checkout -b "master"

创建了主分支,此时

git push -u origin master

将工作推到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'

如果您是第一次使用Git,则需要配置Git安装,包括:

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

git config --global user.name "Your Name"