Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub - prevent collaborators from using push -f

Is there a way to prevent force push into a branch or repository?

I want to stop important branches from having their history rewritten either accidentally or intentionally. How do people deal with this in larger development teams?

Ideally, in my view, would possible to lock few branches per repository, and prevent everyone, other than the repository owner from doing a force push into them.

like image 545
Alex G Avatar asked Feb 23 '11 17:02

Alex G


People also ask

How do I restrict collaborators in GitHub?

Next to the organization, click Settings. In the "Access" section of the sidebar, click Member privileges. Under "Repository outside collaborators", deselect Allow repository administrators to invite outside collaborators to repositories for this organization. Click Save.

Can collaborators push GitHub?

Collaborators on a personal repository can pull (read) the contents of the repository and push (write) changes to the repository.

How can we prevent branches to certain users in GitHub?

Restrict who can push to matching branches You can enable branch restrictions if your repository is owned by an organization using GitHub Team or GitHub Enterprise Cloud. When you enable branch restrictions, only users, teams, or apps that have been given permission can push to the protected branch.


1 Answers

This is easy to do with Git with a pre-receive hook. Of course, this requires that you are actually able to install hooks, and for obvious reasons, GitHub doesn't allow you to upload arbitrary executable files to run on their servers :-)

In general, the workflow with Git or really any distributed version control system, is that you don't allow other people to push to your repository. Instead, you pull from theirs. This requires a much lower level of trust. So, this would be workaround number 1: don't let them push, have them fork and then pull from them. That way, you can control what goes into your repository.

Another workaround would be to set up your own staging repository on a server you own, where you can install your own Git hooks. You can configure a pre-receive hook which denies pushing if it's not a fast-forward and post-receive hook which automatically forwards all pushes to GitHub. Of course, this means that you lose many of the benefits of using GitHub in the first place.

As a third workaround, you could use multiple repositories. This is a combination of the two other approaches: have one repository that your collaborators can push to and another one that only you have access to, that you pull into from the first repository.

At any rate, you should file a feature request with GitHub (especially if you are a paying customer!) since this seems to be a useful feature.

like image 123
Jörg W Mittag Avatar answered Sep 20 '22 10:09

Jörg W Mittag