The question is in PURE GIT not GitHub, GitBucket, GitLab and such.
Is there a way with hooks or anything else, that I can catch the command someone is trying to delete a remote branch ?
Something like the command "push --delete origin branchName"
pre-push or update hooks, doesn't know if a "delete" is executed.
It's very weird that accidentally or without understanding someone can, very simply, delete even a main branches like "master". Its correct that everything could be restored, but why all the hassle ? no way I can mark it as protected or at least some hook that I can check if it is being done ?
We only use GIT with GitExtentions, with simple http, we won't switch to other tools.
Thanks, Eli.
The configuration receive.denyDeletes
can be used for this:
$ git config receive.denyDeletes true
See this reference at the very bottom:
This denies any deletion of branches or tags – no user can do it. To remove remote branches, you must remove the ref files from the server manually.
Or from the git config reference:
If set to true, git-receive-pack will deny a ref update that deletes the ref. Use this to prevent such a ref deletion via a push.
This would be set on the bare repository, or with --system
globally for all repositories handled on that system.