阅读(2793) (2)

GitHub 错误:远程 HEAD 引用不存在的 ref,无法检出

2020-08-19 14:38:43 更新

如果已在 GitHub 上删除仓库的默认分支,会发生此错误。

检测此错误很简单;当您尝试克隆以下仓库时,Git 会警告您:

$ git clone https://github.com/user/repo.git
## Clone a repo
> Cloning into 'repo'...
> remote: Counting objects: 66179, done.
> remote: Compressing objects: 100% (15587/15587), done.
> remote: Total 66179 (delta 46985), reused 65596 (delta 46402)
> Receiving objects: 100% (66179/66179), 51.66 MiB | 667 KiB/s, done.
> Resolving deltas: 100% (46985/46985), done.
> warning: remote HEAD refers to nonexistent ref, unable to checkout.

要修复此错误,您需要成为 GitHub 上仓库的管理员。 您需要更改仓库的默认分支

之后,您可以从命令行获取所有可用分支的列表:

$ git branch -a
## Lists ALL the branches
>   remotes/origin/awesome
>   remotes/origin/more-work
>   remotes/origin/new-master

然后,您可以切换到新分支:

$ git checkout new-master
## Create and checkout a tracking branch
> Branch new-master set up to track remote branch new-master from origin.
> Switched to a new branch 'new-master'