git init
git add file1.csv
git 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 any
error: 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
?我什至尝试使用新的空目录和新的空仓库(再次)执行此操作,但得到了相同的结果。
最佳答案
这是 master
与 main
争论的令人不快的结果。
您的本地GIT客户端创建了一个默认分支master
(当您使用git init
初始化存储库时),但是GitHub上的远程存储库没有master
-而是默认分支称为main
。
解决方案 A - 如果您想将分支命名为 master
运行 git push -u origin master
而不是 git push -u origin main
或 解决方案 B - 如果要命名分支 main
在 git 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/