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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12613793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:40:40  来源:igfitidea点击:

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

gitbranch

提问by mistaecko

I don't understand the second line in the output to git branch -l -a: remotes/origin/HEAD -> origin/master.

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

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

Is that a leftover from another operation? Should I clean it up? And how would I do that?

这是另一个手术的剩余物吗?我应该清理它吗?我该怎么做?

Usually I work with git on the cli, but on this local repository I experimented with TortoiseGitto find an easy git workflow for a friend.

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

采纳答案by VonC

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.

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

See also:

也可以看看:

Note: you need to use git branch --list(or git branch), not git branch -l.

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

回答by Colin D Bennett

You can use git remote set-head origin -dto delete the origin/HEADsymbolic ref, or git remote set-head origin -ato query the remote and automatically set the origin/HEADpointer to the remote's current branch.

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

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

origin/HEAD基准是可选的。它仅作为一种语法快捷方式:如果它存在并指向origin/master,您可以简单地使用 specific origin,否则您将指定origin/master

The git remote(1)man page describes this:

远程Git(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.

设置头

设置或删除指定远程的默认分支(即符号引用 refs/remotes//HEAD 的目标)。不需要远程的默认分支,但允许指定远程的名称代替特定分支。例如,如果 origin 的默认分支设置为 master,则可以在通常指定 origin/master 的任何地方指定 origin。