2

Given the following scenario:

o-o- ... -o-o-o      master
|         |`-o-o     feature1
|         `-o-o      feature2
|             \
 `-o-o-o-o-o-o-o-o   develop

I have a master where all new branches should originate from. While developing stuff everythin is deployed to the develop branch which is rolled out on the test server.

Because it did happen from time to time in the past i want somehow deny branching from anything except master. Is that possible via some git hook?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Andy
  • 726
  • 2
  • 6
  • 15
  • Yes, it is possible, but it is difficult to identify the originating branch, for example if it is branched before the separation between `master` and `develop` – CharlesB Sep 26 '13 at 12:07
  • See [Finding a branch point with Git?](http://stackoverflow.com/q/1527234) for finding the branch point. From there you can check whether the branch point is in master, develop, or both, and deny the push if it comes from master – CharlesB Sep 26 '13 at 12:25
  • thx - will have a look into that, but do you know which hook should be used for that kinda task? – Andy Sep 26 '13 at 13:23
  • it's the pre-receive hook – CharlesB Sep 26 '13 at 13:32
  • I assume your project has a central repository with which all developers synchronize, and you want to check the history being pushed there. Then you need `pre-receive` hook. It is not possible to use `update` hook as some other branches may be waiting to get updated and you want to reject unwanted history as a whole. Is it acceptable for a feature branch to contain a part, where the history branched and merged again before push? Is it acceptable for a feature branch to copy half of the commits of another feature branch to comply with this branching policy? – Palec Nov 05 '13 at 09:06
  • 1
    It will be really hard if not impossible to enforce this policy programmatically. If you want just a tool for the developers to prevent accidental branching from a bad point in history, you may want to provide them with an informative `post-checkout` hook for use in their local repositories. – Palec Nov 05 '13 at 09:31

0 Answers0