一、问题
在使用git将本地项目上传到github上时,出现了以下错误:
error: src refspec xxx does not match any / error: failed to push some refs to
二、 错误产生的原因(操作)
1、在 github 新建了一个工程,
2、本地初始化 ,并关联新建的github地址,在 pull 的时候发现报错
3、发现现在建的 github 工程默认名为了 main
(后面发现由于受到"Black Lives Matter"运动的影响,GitHub 从今年 10 月 1 日起,在该平台上创建的所有新的源代码仓库将默认被命名为 “main”,而不是原先的"master"。)
4、所以 pull 和 push 都会报错
三、问题解决方法
分析原因:
估计是由于仓库名称不一样,导致远程和本地的仓库不能关联上
解决方式:(方法不唯一,仅供参考)
统一远程和本地的仓库名称即可
1、把本地的 master 仓库名称修改为远端的 main
重命名命令: git branch -m oldBranchName newBranchName
2、然后,push 就好了
附录:
(网路上其他方法参考)
本地文件上传github 报错error:src refspec master does not match any
git push origin master
可能存在原因:
本地文件与github上的文件有冲突
本地需要提交的文件中存在空文件
本地的origin和remote origin/master 没有建立关联(我出错的原因)
解决方法:
1、针对第三种情况导致的错误,重新建立本地和远端的连接
$ git remote remove origin
$ git remote add origin git@github.com:XXX/XXX.github.io.git
$ git push origin master
2、针对第一、二种情况导致的错误
$ touch README
$ git add README
$ git commit -m “change”
$ git push origin master
针对第一、二种情况更详细的说明点击
总结
导致错误的原因就是没有理解 origin 和 master
clone 操作之后,Git 会自动将此远程仓库命名为 origin ,建立指针指向项目的指针master
origin 只相当于一个指针指向你 github 远端的地址(仓库名)/(分支名)origin/master 代表远程分支