soenguy
soenguy

Reputation: 1371

How to restrict branch creation only from a specific branch

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

Upvotes: 1

Views: 566

Answers (1)

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72855

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?

Upvotes: 1

Related Questions