tags:

views:

149

answers:

2

Hi, I was wondering is there a way to prevent 'git push --force' on a repository (only on master branch)?

Assume I have remote git repository and do:

  • 'git push' to 'master'. It works.
  • 'git push --force' to 'branch-1'. It works.
  • 'git push --force' to 'master'. It is rejected.

Is it even possible?

Thanks for any answers and suggestions.

BR, Dawid.

+1  A: 

May be through this configuration:

 receive.denyNonFastForwards

If set to true, git-receive-pack will deny a ref update which is not a fast-forward.
Use this to prevent such an update via a push, even if that push is forced.
This configuration variable is set when initializing a shared repository.

But that would be for all branches, not just master... A hook might be able to give you a better control on that configuration.

VonC
+5  A: 

Setting the configuration variables:

receive.denyNonFastForwards
receive.denyDeletes

will prevent any 'forced' pushes from working across all branches.

If you want finer pre-branch control then you will have to use a 'hook' on the remote repository, probably the 'update' hook.

There is a sample update hook called 'update-paranoid' that probably does what you need (and more) in the git distribution in the 'contrib' folder.

gitweb link

Charles Bailey
+1 for the hook (raw version: http://git.kernel.org/?p=git/git.git;a=blob_plain;f=contrib/hooks/update-paranoid;hb=080cbc1275ac09445136ba429d90b5ec85e92c1c )
VonC