git - 错误 : src refspec main does not match any error: failed to push some refs to <url>

标签 git github

  • 为了练习使用 Github,我在我的计算机上创建了一个新目录,我想将其推送到 Github。
  • 我添加了一个 .csv 文件,仅此而已。
  • 我在 Github 上创建了一个新的 repo,没有初始化 README。
  • 我进入目录,然后在终端中使用以下命令:
  • git initgit add file1.csvgit commit -m "First commit"git remote add origin <Github url from Quick Setup page>git push -u origin main我收到以下错误:error: src refspec main does not match anyerror: failed to push some refs to <url>我搜索了一个解决方案,我遇到了这个:git error: failed to push some refs to remote
    选择的答案说:

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


    git pull --rebase origin master


    git push origin master


    我不明白的是,为什么我的计算机上的 目录和 存储库会发生这种情况?没有对 Github 上的 repo 进行任何提交,所以我为什么要 git pull ?我什至尝试使用新的空目录和新的空仓库(再次)执行此操作,但得到了相同的结果。

    最佳答案

    这是 mastermain 争论的令人不快的结果。
    您的本地GIT客户端创建了一个默认分支master(当您使用git init初始化存储库时),但是GitHub上的远程存储库没有master-而是默认分支称为main

    解决方案 A - 如果您想将分支命名为 master运行 git push -u origin master 而不是 git push -u origin main 解决方案 B - 如果要命名分支 maingit checkout -B main 之前运行 git push -u origin main

    关于git - 错误 : src refspec main does not match any error: failed to push some refs to <url>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64601716/

    相关文章:

    git 将两个文件 merge 为一个并保留历史记录

    git - 取消忽略 .gitignore 中的文件不起作用。我想让 GIT 取消忽略 bin 目录?

    git - 我可以对 GitHub 上的 Gist 提出 pull 请求吗?

    git - git 中的 "Virtual"或 "view"分支(在 github 上)

    git - 我如何 "undo"a --single-branch 克隆?

    Android 工作室 - Gradle - GitHub repo

    xcode - .gitignore 文件,我应该把它放在我的 xcode 项目的什么地方?

    git - 在 Tomcat 上设置远程 Git 仓库

    git - 如何使用grgit描述操作

    GitHub API 单一提交不获取所有文件