1

How could I make sure that the only branches that are pushed to origin are:

  • master
  • bug/*
  • feature/*

?

The behavior should be:

  • If branch name is allowed (one of the above), the branch is pushed to origin.
  • Otherwise, error message is displayed: "You are not allowed to push this branch"

What would be the easiest way to force this?

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746

1 Answers1

1

Try installing a git hook

https://www.kernel.org/pub/software/scm/git/docs/githooks.html

If you're aiming for client side, update hook looks like what you might want.

Otherwise you can implement it on the server side with pre-receive

What you need to do is write a script that will take check to make sure the branch is whitelisted before allowing the push. Returning a 0 exit status indicates ok, anything nonzero will prevent the operation

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
  • 1
    [This answer](http://stackoverflow.com/a/19298300/240443) shows what to do with `pre-receive` to do this in considerable detail. Check out the [linked script](http://web.torek.net/torek/git/pre-receive.sh.txt) for detailed ideas. – Amadan Feb 19 '14 at 05:47