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

我不明白git branch -l -a:remotes/origin/HEAD -> origin/master输出中的第二行。

git branch -l -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

那是另一次手术的残留物吗?我应该清理它吗?我该怎么做呢?

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

42409 次浏览

No, no need to clean up: it is the symbolic branch referenced by your remote repo.
When you clone your repo, you will be by default on the branch referenced by remotes/origin/HEAD.

See also:

Note: on Git versions older than 2.20, you need to use ABC0 (or ABC1), not git branch -l.

You can use git remote set-head origin -d to delete the origin/HEAD symbolic ref, or git remote set-head origin -a to query the remote and automatically set the origin/HEAD pointer to the remote's current branch.

The origin/HEAD reference is optional. It only acts as a syntactic shortcut: If it exists and points to origin/master, you can use specific simply origin where you would otherwise specify origin/master.

The git remote(1) man page describes this:

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.