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

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'

当前回答

2020年:

如果30个以上的答案都无效,您可能需要运行git push origin main(在编写此答案时,master已重命名为main)。

其他回答

我曾经遇到过这个问题,因为我在远程回购上有一个分支,但不是本地的。我做到了:gitfetch&&gitcheckout‘在这里添加远程分支名称’,这解决了我的问题。有时,当您不准备更改时会出现问题,因此,要做到这一点,您需要运行以下git命令:git-add your_file_name.extension或git-add。添加所有更改。此时,您需要通过以下方式提交更改:gitcommit-m'您的提交消息在这里'。完成所有这些操作后,只需通过以下方式将更改推送到远程回购:git推送原点your_branch_name。

如果您在Windows上使用GitBash,请尝试重新启动它。它对我有用!

权限问题?解决方案:分叉

我收到这个错误是因为我没有对存储库的推送权限,所以我不得不分叉它,然后我在分叉的存储库上再次执行了pull、commit和push命令。

您可能忘记了命令gitadd。在gitinit命令之后。

如果您是第一次使用Git,则需要配置Git安装,包括:

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

git config --global user.name "Your Name"