简体   繁体   中英

Block commits and pushes on certain branch on git locally

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM