错误:src refspec main与任何错误均不匹配:无法将某些引用推送到< url> [英] error: src refspec main does not match any error: failed to push some refs to <url>

查看:92
本文介绍了错误:src refspec main与任何错误均不匹配:无法将某些引用推送到< url>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 要开始使用Github,我在计算机上创建了一个新目录,希望将其推送到Github.
  2. 我添加了一个.csv文件,仅此而已.
  3. 我没有初始化自述文件就在Github上创建了一个新的仓库.
  4. 我进入目录,然后在终端中使用以下命令:

git init

git add file1.csv

git commit -m首次提交"

git远程添加来源<快速设置"页面中的Github网址>

git push -u origin main

我收到以下错误:

错误:src refspec main与任何不匹配

错误:无法将某些引用推送到< url>

我搜索了一个解决方案,然后遇到了这个问题:git错误:无法将一些引用推送到远程选择的答案如下:

I searched for a solution and I came across this: git error: failed to push some refs to remote The answer selected says:

如果GitHub仓库看到新提交,而您在在本地工作,我建议使用:

If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:

git pull --rebase原始主机

git push origin master

我不明白的是,为什么在计算机上的 new 目录和 new 回购中会发生这种情况?没有在Github上对仓库进行任何提交,所以为什么我必须 git pull ?我什至尝试使用一个新的空目录和一个新的空存储库(再次)来执行此操作,并且得到了相同的结果.

What I don't understand is, why did this happen with a new directory on my computer and a new repo? No commits were made to the repo on Github so why should I have to git pull? I even tried doing this with a new empty directory and new empty repo (again) and I got the same result.

推荐答案

这是 master main 争论的不愉快结果.

This is an unpleasant result of the master vs main controversy.

您的本地GIT客户端创建了一个名为 master 的默认分支(当您使用 git init 初始化存储库时),但是GitHub上的远程存储库没有 master-相反,默认分支称为 main .

Your local GIT client created a default branch called master (when you initialized the repo with git init), but the remote repository on GitHub has no master - instead the default branch is called main.

解决方案A -如果您要将分支命名为 master

Solution A - if you want to name the branch master

运行 git push -u源主服务器 而不是 git push -u源主服务器

解决方案B -如果您想将分支命名为 main

Or Solution B - if you want to name the branch main

运行 git checkout -B main 之前 git push -u origin main

这篇关于错误:src refspec main与任何错误均不匹配:无法将某些引用推送到&lt; url&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆