question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I accidentally commit locally to protected branches

See original GitHub issue

Please 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

  1. 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.
  2. 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

  1. 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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

7reactions
ampinskcommented, Apr 29, 2019

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

Protected-Branch_01@2x

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.

Protected-Branch_02@2x

⚠️ 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.

Protected-Branch_03@2x

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.

Protected-Branch_B@2x

Feedback welcome! ✨

2reactions
shiftkeycommented, Jun 25, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

git undo commit on protected branch? - Stack Overflow
Show activity on this post. Is there a way to undo commits on a protected branch? I mean, If you pushed an wrong...
Read more >
Protected branches - GitLab Docs
Protected branches can only be deleted by using GitLab either from the UI or API. This prevents accidentally deleting a branch through local...
Read more >
Working with Protected Branches
Protected branches stop you from making unauthorized changes to that branch. However, you can make multiple changes locally or to other non-protected branches....
Read more >
Protected branches · Project · User · Help · GitLab
Configure a protected branch · On the top bar, select Main menu > Projects and find your project. · On the left sidebar,...
Read more >
Undo changes in Git repository | PyCharm Documentation
You can always undo the changes you've made locally before you commit them: ... You cannot undo a commit if it was pushed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found