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

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 remote add origin https://github.com/Name/reponame.git
git branch -M main
git push -u origin main

其他回答

作为解决问题的选项之一:

git push origin HEAD

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

也许GitHub不知道你是谁。

首先,您必须运行:

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

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

我有一个非常长的本地分行名称。

git branch -m new_shorter_branch_name

解决了问题。