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

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 add .

这就是你所需要的。该代码跟踪目录中所有未跟踪的文件。

其他回答

我忘记在提交之后和推送之前执行“git pull-origin master”,这导致了同样的问题:“在git中推送提交时,src-refspec-master不匹配”。

因此,您应该做到:

1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master

对我来说,这似乎是因为我已经完成了提交过程,所以我在尝试再次提交后得到了这个结果。

Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

因为我看到路径是origin/main,所以我将其推到main而不是master,并且它起了作用。

注意:检查以确定主分支是主分支还是主分支。

截至2022年。

万一您在执行gitinit并推送初始提交后仍面临此问题。然后,您可以尝试以下操作:,

git checkout -b "new branch name"
git push origin "new branch name"

您的代码将作为新分支推送。

我收到这个错误,因为我的本地分支名称与我试图使用git push origin创建的新远程分支不匹配。

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

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