Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I can see the case for a local UI option (perhaps even on by default) that warns you when you make changes to a local branch that's tracking a remote branch that's marked as 'protected' there. The option could also have a setting where it outright stops you from making that change.

Of course, you could always opt out of that setting.

Git doesn't know what 'protected' means, but you could teach it with a relatively small change to its code. Similarly, it might be useful to teach git about 'volatile' branches (in the same sense as C's volatile variables); a volatile branch is one where git would always checks for upstream changes first before any operation. Eg origin/main would typically be marked as both protected and volatile.

Again, volatile would be something you can override locally, but it might be useful as a default.



The logic you're suggesting can easily be implemented with a Git hook:

https://stackoverflow.com/questions/40462111/prevent-commits...

Alternately, you can simply not check out that branch locally at all, and then you'll never have to worry about accidentally committing to it.


Also, many repo hosts have branch protection tools, and VS Code has a setting git.branchProtection to list branches which you want VS Code to remind you not to commit to, which can be handy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: