为什么我的`git branch -l -a`输出中有`remotes / origin / HEAD-> origin / master`条目?

Why is there a `remotes/origin/HEAD -> origin/master` entry in my `git branch -l -a` output?

我不理解输出到git branch -l -a的第二行:remotes/origin/HEAD -> origin/master

1
2
3
4
git branch -l -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

那是其他操作的残余吗? 我应该清理吗? 我该怎么办?

通常我在cli上使用git,但是在这个本地存储库中,我尝试使用TortoiseGit为朋友找到一个简单的git工作流程。


不,不需要清理:这是远程仓库所引用的符号分支。
克隆存储库时,默认情况下,您将位于remotes/origin/HEAD引用的分支上。

也可以看看:

  • " Git:在裸仓库中更改Active Branch的正确方法吗?"
  • "如何更改Git远程HEAD以指向除" master"之外的其他内容"
  • " origin/HEAD如何设置?"

注意:您需要使用git branch --list(或git branch),而不是git branch -l


您可以使用git remote set-head origin -d删除origin/HEAD符号引用,或使用git remote set-head origin -a查询遥控器并自动将origin/HEAD指针设置为遥控器的当前分支。

origin/HEAD参考是可选的。 它仅充当语法快捷方式:如果存在并指向origin/master,则可以仅使用特定的origin,否则将指定origin/master

git remote(1)手册页对此进行了描述:

set-head

Sets or deletes the default branch (i.e. the target of the
symbolic-ref refs/remotes//HEAD) for the named remote. Having a
default branch for a remote is not required, but allows the name of
the remote to be specified in lieu of a specific branch. For example,
if the default branch for origin is set to master, then origin may be
specified wherever you would normally specify origin/master.