I accidentally commit locally to protected branches
See original GitHub issuePlease describe the problem you think should be solved
“I frequently commit locally to a branch that’s protected on GitHub and one that I can therefore never push to. After I realize I committed to the wrong branch, then I have to either Undo however many commits I’ve made, switch branches, and do the commits again on a new branch or I have to use a different method to get those commits over to a different branch.”
Branches on GitHub are protected for a reason (so there’s a particular level of scrutiny before code makes its way onto them), and it doesn’t make sense why GitHub Desktop shouldn’t have knowledge of this central concept of GitHub’s overall model.
A version of this was brought up in #1021 and we explored this a bit in #4647, but I’d like to refocus the discussion around the problem before we move toward solutions.
Reference GitHub protected branch docs: https://help.github.com/en/articles/about-protected-branches
Open questions
- Is this only relevant for protected branches, or are there other instances where people never want to commit to a particular branch? One that has come up previously is the default (often
master
) branch, but I want to question that assumption. - If a branch is protected, is there ever a reason someone would want to commit to that branch locally? Our assumption thus far is no.
If you have thoughts about either of the open questions, we’re really interested in understanding this better.
Success metrics
- If our assumptions are correct and we succeed in solving this problem, we’d anticipate that the number of commits in Desktop to a branch that’s protected would drop significantly (by at least half, or potentially even to zero).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:14 (14 by maintainers)
Top GitHub Comments
I did some thinking here and chatted with @billygriffin. We believe this problem would better served by not letting users commit to protected branches in the first place, rather than letting them move commits after the fact. Here’s the flow we’re proposing:
Proposed flow
Lock commit area
If a branch is protected, we’ll update the commit area to show a warning, and prompt you to switch your branch
Switch branch
Clicking on
Switch branch...
will open the branch panel and allow you to choose a branch to switch to, or make a new branch.⚠️ We decided we would skip the stashing dialog here because it is implied that you’ll be bringing your change with you, and we’d rather skip the unnecessary click.
Commit to new branch
Your changes would follow you to the new branch, and you can commit from here.
Alternate option
If this flow is too blocking, an alternate option would be to not disable the commit area, and simply show a warning that the branch is protected.
Feedback welcome! ✨
Gonna unassign myself from this issue now that #7826 is merged and ready to go out for the beta.
@billygriffin I’ll defer to you about whether you want to leave this open post-beta and how to deal with feedback.