2

I'm working on a project with my colleges, and we have decided that all code that goes into the develop branch should be made as a pull request on BitBucket(Or git hosting of choice). This means that we don't want any developer to be allowed to directly push to either the develop or master branch.

BitBucket has a setting to prevent push to these branches by certain users. but.
1. You can't place all members in this list
2. Users placed in this list cannot merge pull requests either

What I want is a way to locally prevent both commits on the develop and master branch. Is there an easy way to do this?

1 Answer 1

1

BitBucket has a setting to prevent push to these branches by certain users. but.

  1. You can't place all members in this list
  2. Users placed in this list cannot merge pull requests either

Bitbucket lets you limit write access to certain branches. If you have a relatively small group where everybody knows everybody else, then allow everyone write access but make a rule that nobody should push directly and nobody should merge their own pull request. That usually works fine -- everybody can see changes to the repo, so it'll be pretty clear if somebody violates the rule.

For larger groups, define a set of users who are allowed to review and merge pull requests from others. This is how most open source projects work -- anybody at all can send a pull request, but only a small group of trusted committers can accept and merge the contributions.

The same strategy applies even with a small group, if necessary: give just one or two people commit privileges, at least at first, so that only they can merge pull requests. You can't block everyone from having write access, though, or else nobody can merge and those branches can never change.

If you still want to block push/commits locally, you can use git hooks
block pushes from certain branches locally
block commits on certain branches locally

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks; although I would still like to be able to block any commits to develop or master to prevent mistakes from happening. Most of the team is pretty new to git, so this is a real possibility.
@sigsve Edited to address that, but perhaps I should also say that there's really no difference between being able to merge a PR and being able to push to a repo. Also, remember that you're using a revision control system that remembers every change, so if somebody does screw things up you can always fix it by reverting back to a previous version.
Of course, but, we very much do not want any code to go into the repository without having been code reviews(We use pull requests for this). And although we can always revert, it's a pain. I would rather just make sure we don't make a mistake to begin with.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.