desktop: Detached HEAD + Uncommitted Changes = Cannot Switch Branch

Description

There is a problem when switching from a Detached HEAD to a branch if you have uncommitted changes.

Version

  • GitHub Desktop: 2.0.3
  • Operating system: Microsoft Windows [Version 10.0.17134.765]

Steps to Reproduce

  1. In GitHub Desktop, Clone a repository that has some commits
  2. Make some arbitrary change, so that you see at least one file on the Changes tab in GitHub Desktop
  3. On the History tab in GitHub Desktop, right-click any commit and click on Copy SHA
  4. In Git Bash (or anything that can run a git command), run git checkout <paste> (paste the Commit SHA you copied)
  5. In GitHub Desktop, try to switch from Detached HEAD to any branch

Assuming you cannot switch (which is the case for me every time), here’s what I do next to get around it:

  1. In Git Bash, run git add . and git stash to stash all changes
  2. In GitHub Desktop, try to switch from Detached HEAD to any branch

Expected Behavior

Step 6 should switch to the selected branch

Actual Behavior

Step 6 does not switch to the selected branch, it stays on the Detached HEAD.

Additional Information

On Step 8, I get this cute popup (the branch I tried to switch on Step 6 was master)

image

Logs

2019-06-06.desktop.production.log

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I actually had to come here and search for “detached head” to find out why I wasn’t able to switch branches. The branches remain selectable but nothing happens when clicked, so it genuinely comes across as if Github Desktop is bugged.

If taking changes won’t be implemented, the ideal solution in my eyes would be a popup asking if you want to discard the changes or stay in the same branch. That’d be miles better than just ignoring any commands until the changes are discarded.

Just my two cents - Given a lack of a way to enter Detached HEAD mode from GitHub Desktop, I would expect that switching from a Detached HEAD to a Branch always brings your changes to that branch, barring any conflicts. (If a feature is ever added so that you could switch to Detached HEAD from GitHub Desktop, I would think differently)

@the-avid-engineer I’ve been able to reproduce it, and the problem area is here:

https://github.com/desktop/desktop/blob/46291625ec0f5e72350aa714775dca16f893ee51/app/src/ui/app.tsx#L1672-L1676

We’ve baked an assumption into the “Switch branch” dialog setup that you’d be on a valid branch, which gets skipped when you are on a detached HEAD, so the dialog is never shown.

The simplest workaround - “just show me the dialog” - doesn’t quite solve this. Here’s what it looks like:

Screen Shot 2019-06-06 at 4 29 17 PM

This seems reasonable, but look at that first option. We can’t stash this at some arbitrary SHA, because that’s not something you’ll be able to get back to easily - which was the goal of this feature.

I’m gonna cc @iAmWillShepherd and @outofambit at this point for their thoughts on what we should be doing here, as well as cc @desktop/product for 👀 and thoughts if they have them.

I’ve marked it as priority-3 because this is the first report about it, but I could promote it to priority-2 because preventing the user from switching branches feels significant enough to prioritize.