git push -u origin main错误(master以外的其他名称)

时间:2020-08-03 08:24:42

标签: git rename naming-conventions git-push

git的命名约定已更改,现在建议对 Master 分支使用其他命名。

尝试将真棒项目初始化为名称为 Main

的新git repo时遇到问题
git init
git add -A
git remote add origin https://github.com/{MYREPO}.git
git push -u origin main

最终抛出以下错误

error: src refspec main does not match any.
error: failed to push some refs to 'https://github.com/{MYREPO}.git'

git版本2.16.1.windows.4

1 个答案:

答案 0 :(得分:2)

解决方案:假设这是全新的仓库,这就是解决方案

git branch -m master main
git push -u origin main

说明

git init创建一个名为masterref)的本地起源

-b <branch-name
--initial-branch=<branch-name>

为新创建的存储库中的初始分支使用指定的名称。

如果未指定,则退回到 默认名称:master

这就是git抛出该错误的原因。

使用git show-ref查看您的引用。 (ref

如果显示refs/heads/master,则可以使用git branch -m master {name}

将其重命名为所需的名称。
相关问题