0

I'd like to restrict myself from creating branches from some other branches. Basically, I want to be able to create a new branch only from master.

I know there are hooks available, but nothing seems to be prior to checkout.

Also, I don't mind if there's just a message showing up in my console instead of completely being unable to create the branch. Even simple warning message will be enough.

Is there any way to do that?

PS: I'm only talking local git, not server-side which could prevent me from pushing

kosist
  • 2,868
  • 2
  • 17
  • 30
soenguy
  • 1,332
  • 3
  • 11
  • 23
  • 2
    Possible duplicate of [Git hook when a new branch is created and/or pushed](https://stackoverflow.com/questions/14297606/git-hook-when-a-new-branch-is-created-and-or-pushed) – Lasse V. Karlsen Nov 06 '18 at 09:54

1 Answers1

1

I suppose you could use some combination of hooks to prevent this but it's not really something that's doable. Creation of a branch is just creating a simple file with a hash inside it. That's a very fundamental operation on git and I can't see a straightforward way of restricting what it can point to.

Suppose your master points to a9456b and you say git branch foo a9456b, it will still create a branch that starts at master. How would you prevent this?

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169