1

I am trying to use GIT hooks to restrict commit message formats (e.g. "must start with #") on my main branches only: dev, master. I do want to allow contributors to have their own custom commit messages on their private branches.

Example: If someone has X commits on their private branch "commit1"...."commitX", can I use hooks to block them from merging to or into dev/master branches telling them that only commits starting with "#" are allowed?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Codey
  • 171
  • 7
  • What code have you written already? Where are you having problems? (That's how stackoverflow works.) – Mort Jan 06 '17 at 02:42
  • What are you trying to accomplish by enforcing this rule on commit messages? Seems a bit draconian. – kylieCatt Jan 06 '17 at 05:39
  • Yes i agree. However this is not my repo, it's my employer's, and I am trying to get a bit more freedom of commits on private branches, as i do like to stack my changes, and following convoluted commit message rules for every checkpoint doesn't help – Codey Jan 06 '17 at 16:50

1 Answers1

1

can I use hooks to block them from merging to or into dev/master branches

Not easily one the client side (because they need to be deployed on all clients, and they can be bypassed anyway)

What is usually done is set up a server-side hook which will block any push including commits with an incorrect message.
The update hook can be more suited for this than the pre-receive one.
See "Customizing Git - An Example Git-Enforced Policy"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250