Skip to content

Branches() silently drops any remote branch whose name ends in /HEAD (e.g. origin/release/HEAD) #225

Closed

Description

@matt-edmondson

What's wrong

GitBranchParser.Parse (GitIntegration/Parsing/GitBranchParser.cs:~50-58) skips every remote-tracking ref whose full name ends in /HEAD:

bool isRemote = fullRefName.StartsWith(RemotePrefix, StringComparison.Ordinal);
if (isRemote && fullRefName.EndsWith(HeadSuffix, StringComparison.Ordinal))   // HeadSuffix = "/HEAD"
{
    continue;
}

The intent is to hide the symbolic refs/remotes/<remote>/HEAD. Because the check is a suffix match, it also removes real branches. Git accepts release/HEAD, and any other <x>/HEAD, as a branch name (git check-ref-format --branch release/HEAD succeeds).

Reproduction (git 2.43)

git -C up branch release/HEAD main
git -C down fetch
git -C down branch -r
  origin/HEAD -> origin/main
  origin/feature
  origin/main
  origin/release/HEAD          <- git lists it

repo.Branches().ExecuteAsync() on down returns:

feature remote=False
main remote=False
origin/feature remote=True
origin/main remote=True      <- origin/release/HEAD is missing

A local branch with the same name is kept; only the remote-tracking copy disappears. So RemoteOnly() listings, and any "branches on the server" view, lose it with no error.

Suggested fix

  • Skip the ref because it is symbolic, not because of how its name ends: add %(symref) to GitOutputFormats.ForEachRefFormat (GitIntegration/Parsing/GitOutputFormats.cs) and skip a remote record when that field is non-empty. This matches git branch -r, which shows origin/HEAD -> origin/main as an alias and lists every real branch normally.
  • Correct the nearby remark in GitOutputFormats.cs: with :lstrip=2, the HEAD ref shortens to origin/HEAD, not to the bare origin.

Acceptance

  • A parser test in which refs/remotes/origin/release/HEAD (not symbolic) is returned and refs/remotes/origin/HEAD (symbolic) is not.
  • An integration test with a remote branch named release/HEAD.

Activity

  1. matt-edmondson commented on Oct 17, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions