学无先后,达者为师

网站首页 编程语言 正文

遇到一个git的大坑 src refspec master does not match any error: failed to push some refs to

作者:hello-java-maker 更新时间: 2022-04-14 编程语言

今天本来想把内容上传到git仓库去,但是折腾了好久一直报错。

错误信息是这样的。

error: src refspec master does not match any error: failed to push some refs to 

这个错误其实是很常见的错误,但是一直没有解决,试了很多方法,结果都不行。

这个问题的常见原因有:

1.本地git仓库目录下为空
2.本地仓库add后未commit
3.git init错误
4.没有先进行git pull

但是我的都不是这些原因。我的问题在于,我的这个本地项目早就存在了,但是一直没有使用git,于是我想直接在项目中创建git仓库,直接git init,就是这种方式导致的。

常规方式是:创建文件夹->git init -> git add . -> git commit -> git push.

我的方式是:已有陈旧项目->git init -> git add . -> git commit -> git push.

因此,导致我一直失败,所以,只需要采用常规方式即可解决问题!

更新

最新的一个问题是,现在github的默认分支为main,但是,我一直认为是master,所以,在提交时,需要提交到main,而不是master。
使用:git push origin main,即可。

原文链接:https://blog.csdn.net/sihai12345/article/details/115432052

栏目分类
最近更新