Restrict branch X to be merged only from one specific branch Y in Github

Viewed 2803

My repository belongs to an organization I created. I want to prevent mistakes during pull requests. For example, accidentally allowing the master branch to be merged from different branch then development.

How can I accomplish this?

1 Answers

If you make master a protected branch, then only those with elevated access to the protected branch can push to it, and/or merge in pull requests (ideally no one ever pushes directly without a pull request for review, unless fixing a merge/commit issue). There isn't really a need to make sure they only come from development (in my opinion), that's just process that you need to agree on with everyone who is a lead/senior dev that is given those rights.

Git gives plenty of tools to revert things for the rare cases where someone messes up. Sure you'll likely end up with an extra commit or two, but that's not something disastrous. You lose so much more productivity by completely rigid, top-down process than by being a little looser and training people about best practices and making them better developers along the way through training and correction (when the odd error does occur).

At least that's my experience.

Related