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

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 HEAD

其他回答

这对我有用:

只需签出主分支:

git checkout -b master
git add .
git push origin master

或者使用——强制改变。

git push origin master --force

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

当您在一个特定的分支中并尝试推送另一个尚不存在的分支时,也会发生这种情况,例如:

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

两种可能性:

1-要么忘记包含.gitignore文件。

以下是所需的所有步骤:

在远程上创建一个空的Git存储库,在本地创建.gitignore文件。GitHub在这里列出了一些示例启动终端,然后在项目中执行以下命令:git remote添加原点YOUR/origin.gitgit添加。gitcommit-m“初始提交或首次提交的任何消息”git push-u原始主机

2-或者您正在尝试创建一个新的Github项目。

Github将master替换为main作为默认分支名称。要解决此问题,请执行以下操作:

在本地项目上:删除.git文件夹(如果存在)通过在项目中启动以下操作,重新创建一个干净的存储库:

在终端中:

git init

git add .

git commit -m "YOUR FIRST MESSAGE HERE"

git branch -M main

git remote add origin _GIT_LINK_TO_PROJECT_HERE_

git push -u origin main

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

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