Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git branch delete - HOOK

I have ready many articles about protecting remote branches...

I however would like to capture in a git hook the following LOCAL repo command:

git branch -d abranchthatshouldnotbedeleted

I would like to hook that command and analyze it against an branch list file of "protected branches" that I made and do a simple check to allow or deny the delete.

Certain branches of mine are now locked in a stated where they are managed now and must be protected.

like image 304
user1832576 Avatar asked Sep 12 '26 04:09

user1832576


1 Answers

Since GitHub doesn't allow pre-receive hook (only post-receive ones), I would recommend pushing to an intermediate local repo, protected by Gitolite (an authorization layer, through ssh or http access to your git repo).

Gitolite can help code all kind of access rules, including protecting a branch against deletion.

If the push is allowed, then a post-commit hook can push that automatically to GitHub.

like image 162
VonC Avatar answered Sep 14 '26 00:09

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!