-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I accidentally commit locally to protected branches #7023
Comments
This comment has been minimized.
This comment has been minimized.
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 flowLock commit areaIf a branch is protected, we'll update the commit area to show a warning, and prompt you to switch your branch Switch branchClicking on Commit to new branchYour changes would follow you to the new branch, and you can commit from here. Alternate optionIf 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! ✨ |
The designs look great and both easy to comprehend. Some things I was thinking about in regards to this:
|
Thanks for the feedback and great questions @tierninho! Initial thoughts below:
They would just be in the same state as before, which IMO is completely reasonable. I think it's ok to assume that if they know they are on a protected branch and need to switch, they likely aren't going to choose another one to move their work to.
Good question - that feels really edge-casey and I'm not sure we need to solve for it. But we should ensure that the cadence at which we know about protected branches is frequent enough to make this a fairly unlikely scenario.
By "state of the branch," do you mean whether it's protected or not? If so, I'm willing to take that risk until we hear otherwise. I don't think people are frequently protecting and then unprotecting branches.
Not sure I understand this question. It's just a matter of whether or not the user can push to that branch because it's protected. We could do something similar to handle forks, but since that's a separate repo and not just a different branch within the same repo, that feels more involved and a separate problem statement. |
I was reading about protected branches and saw "If your repository is owned by an organization, you can restrict users or teams from pushing to a protected branch" here. For the MVP version, I agree that a protected branch is just that, full stop. 💯 |
Update: GitHub allows repo admins to exclude admins from branch protections, and also to whitelist users or teams to allow them to push to protected branches (shoutout to @tierninho for bringing it to our attention). Therefore, it seems like we have two choices here:
Unless it's really easy to get the knowledge required to differentiate to support (1) above, we probably ought to start with (2) as the first iteration and then potentially build out from there. |
This bit of information you're looking for is what you get when you request the Get Repository endpoint as an authenticated user. You'll see this
EDIT: Oops, I missed this comment. This should be covered by the List user teams endpoint. I'm less familiar with this API (and how Branch Protections itself is returned as JSON) but I think those should cover both gaps. |
@billygriffin we'd need new places to cache the branch protections (per repository) and the teams a user belongs to (per account) but I think that's not too much additional work - we have the infrastructure to support this. |
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. |
Thanks @shiftkey! I'd like to keep it open for further iteration since we do intend to do that. |
@NickCraver thanks for the feedback. I'll leave it to others to take this further (I'm out on holidays next week) but I'll provide insight into the API details based on my experience fleshing this out:
API access to this list in a branch protection is only available for We're mindful of this gap, and we're talking through it with the team that owns this area. Hopefully we can figure out a solution that'll eventually be available in GHE. |
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
master
) branch, but I want to question that assumption.If you have thoughts about either of the open questions, we're really interested in understanding this better.
Success metrics
The text was updated successfully, but these errors were encountered: