0

Is it possible to create a Git hook that would prevent creating a brach name not meeting some specific requirements?

Say I want to allow only branch names composed with [-a-z/] (small letters, / and -, i.e. disallow capital letters).

Commit or post hooks are not good enough because someone can do:

git checkout develop
git checkout -b feature/WrongBranchName

Sure, in this case I can prevent pushing such branch to remote or adding new commits to it, but the branch has already been created.

Greg
  • 8,230
  • 5
  • 38
  • 53
  • You really shouldn't try to impose restrictions on what users call their local branches. If you can prevent branches from being created on your server that don't follow your naming convention, that's the place to do it. – user229044 Sep 20 '18 at 18:34
  • We have restrictions because our devs don't remember that two branches that differ only with cases of letters are the same on Windows but not the same on Linux (Windows is used for development but Linux to run CI infrastructure). Then we have problems with refs that can't be updated or branches that can't be deleted without special tricks that take other deverloper's time. It's a corporate environment and we don't control the servers so have to deal with it using other methods. – Greg Sep 22 '18 at 19:45

1 Answers1

1

No. There isn't a git hook for branch creation.

Adam
  • 4,180
  • 2
  • 27
  • 31