3

In a common (git-based) development workflow, one maintains a master branch and a next (or dev) branch which is used for testing purposes:

  • feature branches begin from master and are merged into next for testing. If deemed stable, feature branches can be merged into master.
  • master is periodically merged into next
  • next is periodically rewound (say, after a release).
  • The next branch should never be merged into the master branch

It would be useful to be able to automatically prevent merges of next into master, either directly or via another branch based on next. How can one accomplish this using git?

Note: as described in this question, it is possible to use git hooks to prevent these types of merges on a remote repository one has full access to. However, this is (presumably) not possible with services like BitBucket or GitHub, so I seek a solution that works with a local repository, or one which can be used with a remote repository that one only has limited administrative access to.

Community
  • 1
  • 1
Patrick Sanan
  • 2,375
  • 1
  • 23
  • 25
  • Why don't you install the hook locally? – Aaron Digulla Sep 03 '14 at 15:07
  • The hook in the link is an update hook, which only makes sense for a remote repository. Perhaps it's simple, but how would one translate that into a local hook? – Patrick Sanan Sep 03 '14 at 19:30
  • 1
    This seems like a fantastic question and is one I need an answer to too. It's extraordinary and quite troubling that it doesn't have far more attention and a hook based answer, as it seem crucial to safe use of this workflow. I'm wanting to do this having cost my team a pile of time and annoyance in exactly the way the OP describes (with the "via another branch" variant). – Benjohn Nov 19 '15 at 15:42

1 Answers1

1

When you really want to use Github/Bitbucket, then don't give anyone write access to your repo. Only accept pull requests. That way, you can check the request which merges it contains and reject them if you see something that you won't want.

A way to automate this is to create a local repo, add a hook which does the checks and then pull the pull request into the new local "validation" repo (which shouldn't be your normal work repo, so you can always throw it away).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820