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

GitBranch

Git Problem Overview


I don't understand the second line in the output to 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 TortoiseGit to find an easy git workflow for a friend.

Git Solutions


Solution 1 - Git

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 git branch --list (or git branch), not git branch -l.

Solution 2 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmistaeckoView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitColin D BennettView Answer on Stackoverflow