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
- In GitHub Desktop, Clone a repository that has some commits
- Make some arbitrary change, so that you see at least one file on the
Changestab in GitHub Desktop - On the
Historytab in GitHub Desktop, right-click any commit and click onCopy SHA - In Git Bash (or anything that can run a git command), run
git checkout <paste>(paste the Commit SHA you copied) - In GitHub Desktop, try to switch from
Detached HEADto any branch
Assuming you cannot switch (which is the case for me every time), here’s what I do next to get around it:
- In Git Bash, run
git add .andgit stashto stash all changes - In GitHub Desktop, try to switch from
Detached HEADto 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)

Logs
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (6 by maintainers)
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.
https://github.com/desktop/desktop/issues/7719
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:
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-3because this is the first report about it, but I could promote it topriority-2because preventing the user from switching branches feels significant enough to prioritize.