Elegant solution to prevent force push on master only
I'm trying to figure out a good way to prevent developers from force pushing master with Git. We used GitHub to host our remote repositories so a pre-receive
hook isn't an option. Any other solutions that could easily be implemented for a team of developers?
As a side note, I don't want to disable force pushing in general. Sometimes it is a necessary evil. But that said, force pushing on master cannot happen.
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
GitHub introduced a new feature called "Protected Branches" to prevent force pushing. You can configure it in repository Settings > Branches.