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

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

你可能会看到refs/heads/live

这意味着你应该这样做

git push -u origin live

其他回答

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

只是在这里粘贴:

  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是存储库名称。

2021,GitHub将默认分支名称更改为main。以前它是主人。

我之所以痛苦,是因为我试图向不存在的主服务器推送,而远程的分支是主服务器。确保您使用的分支名称正确。

下面的命令对我有效

git push origin main

我遇到的问题是在尝试重置存储库时。我想删除所有历史记录,什么都不做。然而,您必须至少添加一些要提交的内容,所以我只创建了一个空文本文件gitadd。然后gitcommit-m“重置存储库”。

几天前我也遇到过同样的问题。

如果您现在(2020年)创建了一个新的存储库,那么默认分支是GitHub上的main。

您现在可以在存储库分支中查看GitHub。

您还可以通过运行以下命令检查终端中的分支:

git branch

所以这就是你需要跑步的原因

git push origin main

而不是

git push origin master

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

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