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

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 branch -m new_shorter_branch_name

解决了问题。

其他回答

对于Windows上Cmder中Bash的用户,请确保在新的主目录中创建一个新的.ssh文件夹。

转到主目录cd~。生成ssh密钥ssh-keygen。保持所有输入为空(保持按回车键)将id_rsa.pub文件复制到Github>设置>SSH密钥

我也犯了类似的错误。但Git告诉我:

*** Please tell me who you are.

Run

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

或设置帐户的默认身份。

Omit --global to set the identity only in this repository.

然后错误消失。

缺少或正在跳过git add。或gitcommit可能会导致此错误:

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

要修复此问题,请重新初始化并遵循正确的顺序:

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master

我也有同样的问题。我通过以下步骤做到了这一点:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
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.