Skip to content

GitHub Desktop enters Detached HEAD when switching back to a branch that shares its name with a tag #182

@rafatosta

Description

@rafatosta

The problem

Description

GitHub Desktop Plus enters a detached HEAD state when switching back to a branch whose name is also used by a tag.

The repository contains:

  • Branch: main
  • Tag: main

Initially, everything works as expected. However, after switching from main to another branch and then back to main using GitHub Desktop Plus, the application reports a detached HEAD state.

Release version

Version 3.5.12.0 (x64)

Operating system and distro

Fedora Workstation

Steps to reproduce the behavior

  1. Create a branch named main.
  2. Create a tag also named main.
  3. Open the repository in GitHub Desktop Plus.
  4. Start on the main branch.
  5. Switch to another branch.
  6. Switch back to main.

Specific to GitHub Desktop Plus?

Occurs in both

Log files

No response

Screenshots

Image Image

Additional context

Expected Behavior

The repository should return to:

On branch main

and remain attached to the branch.

Actual Behavior

GitHub Desktop Plus leaves the repository in a detached HEAD state:

HEAD detached at refs/heads/main

Additional Git output:

git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

git rev-parse --abbrev-ref HEAD
HEAD

The repository can be recovered manually by running:

git checkout main

or

git switch main

although Git reports:

warning: refname 'main' is ambiguous.

Root Cause

The issue appears to be related to the coexistence of:

refs/heads/main
refs/tags/main

GitHub Desktop Plus seems to mishandle the ambiguous reference when switching branches and ends up checking out a commit instead of attaching HEAD to the branch.

Removing the tag named main resolves the issue completely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedI agree this feature/bug is valid, and will work on it when I get a chance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions