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

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'

当前回答

我认为问题源于添加和提交node_modules文件夹。

使用git add.时。,您可能会得到无限滚动,就像它添加了几个文件一样。如果是这样,您不仅要添加脚本,还要添加大小较大的node_modules文件夹。

最好的解决方案是创建一个.gitignore文件,在其中粘贴#dependencies/node_modules。

现在,当您添加文件时,Git将忽略node_modules文件夹。

其他回答

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

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

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

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

截至2022年。

我为一个GitHub存储库做了贡献,所以我分叉了这个项目,克隆了它,创建了自己的分支,进行了一些提交,并尝试推送。

此时,我发现我克隆的不是我的fork,而是原始的项目存储库(我没有权限将其推送到)。

所以我更改了.git/config以将原点指向我的存储库。

此时,当我尝试推送时,我收到了错误消息:src-refspec my_awesome_branch不匹配。

我所要做的就是触摸任何文件并提交它(就像你在这个答案中看到的一样):

git touch README
git commit -m "fixing error in my git repo"

然后:

git checkout master
git pull origin master
git push origin master # This will tell my remote repository about my new branch
git checkout my_awesome_branch
git push origin my_awesome_branch # Now it will work
git push -u origin master
error: src refspec master does not match any.

为此,您需要按如下方式输入提交消息,然后推送代码:

git commit -m "initial commit"

git push origin master

已成功推送到主机。

我遇到了同样的问题,并使用以下步骤解决了它:

git pull--重新基数https://github.com/yours主人git添加。gitcommit-m'提交消息'git推送原始主机

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

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