lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Feature for protection against pushing to remote main/master

Open trskare opened this issue 1 year ago • 4 comments

If you forget to switch branch from master/main and press the key P or perhaps you meant to press p (for pulling) you could in theory do something that could have a big consequence if you work against a repo that are used for CD/gitops/configuration management. Sure! Those repos should definitely have branch protection in place anyway to disable force pushing, only merge commits thru PR/branches etc, but lets think worst case scenario and say someone forgets to enable them or they are temporarily disabled.

What about optional protection feature that will give you a big warning you if you try to push against remote master/main branches?

trskare avatar Jul 04 '24 18:07 trskare

I think this may extend beyond "enhancement" to "bug". I just accidentally pushed my main branch locally to remote by pressing "P", despite the fact that branch protection was configured to require a pull request while reviewing. It would be great if it respected the remote branch protection (or even had a confirmation message to make sure you are certain)

Screenshot 2024-07-15 at 8 21 09 AM

navignaw avatar Jul 15 '24 15:07 navignaw

Is that really lazygit's fault if your git service didn't protect the branch? It just does git push in the background.

mark2185 avatar Jul 15 '24 15:07 mark2185

I can do a bit more research and try to repro on a fresh git repo, but I'm pretty sure that the cli git push would fail due to the branch protection rule, so I'm honestly a bit confused how this happened.

navignaw avatar Jul 15 '24 17:07 navignaw

Apologies for the miscommunication. It turns out that this didn't apply because I was an admin of the repo and github (for whatever reason) lets admins bypass branch protections by default, unless this flag is checked. So there's no issue on lazygit's end!

However I'd still like to echo the feature request of adding (maybe an optional config you can set?) a confirmation message before pushing.

navignaw avatar Jul 17 '24 15:07 navignaw