关于 error: refname refs/heads/master not found 的问题

简介: 关于 error: refname refs/heads/master not found 的问题

正文


从 2020 年 10 月 1 日起,在 GitHub 新创建的仓库(repository)会以 main 作为仓库默认分支(default branch),但它不会影响已有的仓库。


当然,GitHub 仍然是支持自定义设置默认仓库名称的,可在 https://github.com/settings/repositories 页面进行设置。


抱歉,废话多了,回到正题。


今天创建了一个新项目 vite-demo,然后想着就用 main 作为默认分支吧。

$ git init
$ git branch -M main


执行以上重命名分支的命令后,发现报错了,如下:

error: refname refs/heads/master not found
fatal: Branch rename failed


原因是本地代码还没提交(commit),因此没办法进行更名操作。正确的步骤应该是先 init → add → commit,接着才能进行更名操作。

在本地修改 Git 的默认分支名称,可通过以下命令调整:

git config --global init.defaultBranch <default-branch-name>


目录
相关文章
|
开发工具 git
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
|
5月前
|
开发工具 git
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
612 1
|
5月前
svn: E175002: Commit failed (details follow): svn: E175002: Unexpected HTTP status 502Bad Gateway on
svn: E175002: Commit failed (details follow): svn: E175002: Unexpected HTTP status 502Bad Gateway on
155 1
|
消息中间件
failed to open log file at ‘/var/log/rabbitmq/rabbit@9f987b50c687_upgrade.log‘, reason: permission d
failed to open log file at ‘/var/log/rabbitmq/rabbit@9f987b50c687_upgrade.log‘, reason: permission d
292 0
|
6月前
|
NoSQL Redis
解决(error) ERR Errors trying to SHUTDOWN. Check logs.问题~
解决(error) ERR Errors trying to SHUTDOWN. Check logs.问题~
176 0
|
开发工具 git
【Git】push代码时候报错,出现fatal: unable to access xxx Recv failure: Connection was reset
【Git】push代码时候报错,出现fatal: unable to access xxx Recv failure: Connection was reset
219 0
|
存储 开发工具 git
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
329 0
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
|
开发工具 git
git push报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
git push报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
189 0
未解决:dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/-1.diff.rm5mTN
未解决:dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/-1.diff.rm5mTN
123 0
下一篇
无影云桌面