[Git]克隆仓库报错warning: remote HEAD refers to nonexistent ref, unable to checkout

问题:

从远程仓库clone项目,报错warning: remote HEAD refers to nonexistent ref, unable to checkout,只拉取到了隐藏.git文件夹。

gamin yunjuke % git clone http://git.whizape.com/ck/MF_APP_H5.git
Cloning into 'MF_APP_H5'...
remote: Enumerating objects: 1119, done.
remote: Counting objects: 100% (1119/1119), done.
remote: Compressing objects: 100% (1061/1061), done.
remote: Total 1119 (delta 715), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (1119/1119), 1.11 MiB | 629.00 KiB/s, done.
Resolving deltas: 100% (715/715), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout
gamin yunjuke % cd /Users/gamin/Documents/yunjuke/MF_APP_H5
gamin MF_APP_H5 % git branch

gamin MF_APP_H5 % git branch -r
  origin/master

gamin MF_APP_H5 % git checkout master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'
gamin MF_APP_H5 % git pull
Already up to date.

解决:

1. 查看远程仓库的分支列表

在克隆完成后,进入克隆的仓库目录:

cd MF_APP_H5

运行以下命令查看远程仓库的分支:
注意,这里用git branch获取不到分支明显。

git branch -r

你会看到类似的输出:

  origin/feature-branch
  origin/main
  origin/master

如果 git branch -r 没有列出任何分支,说明远程仓库确实是空的,或者没有任何有效的分支。

2. 手动切换到某个分支

如果远程仓库有分支,你可以手动切换到一个有效的分支。例如,切换到 main 分支:

git checkout main

如果远程仓库的默认分支是 master,而不是 main,可以执行:

git checkout master

这将会切换到你选择的分支并检出代码。

3.拉取项目

切换分支后,重新拉取项目就可以了。

git pull