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

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

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

如果要在原点远程创建新分支,则需要首先在本地创建相同的分支:

$ git clone -b new-branch
$ git push origin new-branch

检查提交标题,因为如果忘记了gitcommit-m“xxxx”命令,就会遇到同样的问题

git commit -m "initial commit"

我遇到了同样的问题,我使用了--允许空:

$ git commit -m "initial commit" --allow-empty
...
$ git push
...

补充

这个问题的一个主要原因是,在克隆新的存储库时,一些Git服务器(如BitBucket)没有初始化其主分支。