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

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 config --global user.email "YOUR EMAIL"
git config --global user.name "YOUR NAME"

其他回答

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

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

下面的命令对我有效

git push origin main

确保分支名称中没有不可见的拼写错误:

git branch

输出:

master
* <U+0096>your_branch_name

有一个不可见的<U+0096>字符,可能是通过粘贴分支名称到达的。

将当前分支重命名为正确的值,然后重试推送:

git branch -m your_branch_name

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

git commit -m "initial commit"

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

更新以前的答案。

此外,别忘了github已经将“Master”更改为“Main”,因此请确保您通过以下方式进行推送:

git push origin main