Elegant solution to prevent force push on master only

Update

Github has since introduced the concept of protected branches. It can be found under Settings -> Branches -> Protected Branches

This “protection” can be enabled for any branch, and for any user, including admins.

More details here – https://help.github.com/articles/defining-the-mergeability-of-pull-requests/


You cannot prevent this in Github.

What you can do is have an intermediate repo on your side, run a pre-receive hook in that to prevent force push and push from this intermediate repo to github and block access for direct push to github. Yeah this is not elegant and you lose lots of features with Github, but I don’t see any other way.

Edit: Just came across this answer, which says the same and gives another workaround: GitHub – prevent collaborators from using push -f

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)