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

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原始主机

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

这是由于存储库仍然是空的。存储库中没有提交,因此没有主分支可以推送到服务器。

这对我有用

决议

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

其他回答

在删除本地计算机上的所有文件后,我也出现了类似的错误,我必须清理存储库中的所有文件。

我的错误消息如下:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

通过执行以下命令解决了问题:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

最初,每个文件都处于未跟踪状态。我们需要将未跟踪的文件从工作目录添加到暂存区,只有这样Git才能开始跟踪这些文件。从工作目录中,我们将文件移动到准备好进行下一次提交的暂存区,这样Git就可以对它们进行快照以创建新版本。您跳过了临时区域,只向临时区域添加了一个文件。

首先转到要推送的本地文件夹,然后执行以下步骤。

初始化

git添加。

gitcommit-m“首次提交”

我确实遇到了同样的问题,但在我的情况下,创建新存储库时,从一开始就按照页面上给出的步骤进行操作。

只是在这里粘贴:

  echo "# YYYY" >> README.md
  git init
  git add README.md
  git commit -m "first commit"
  git remote add origin https://github.com/XXXX/YYYY.git
  git push -u origin master

在GitBash中键入上述内容。XXXX是用户名,YYYY是存储库名称。

当您添加了文件,忘记提交和推送时,就会发生这种情况。所以提交文件,然后推送。

我在尝试将内容推送到GitHub上的新存储库时遇到了这个错误。我在本地创建了Git存储库,并且使用Web GUI(包括一个LICENSE文件)在GitHub上创建了存储库。

在我将LICENSE文件从原本空的GitHub存储库拉到本地存储库后,问题消失了。之后,我可以毫无问题地推进。