简体   繁体   中英

Disable `git push --force` locally

I would like to disable git's --force flag usage on local machine completely (globally for all the repos I have). I assume it's possible with some bash hook, but where can I read more info about creating one?
Ideally the behavior would be like this: every time I try to use --force flag in any push command in any repository - my terminal will show the command abortion and tell me that it's forbidden.

UPDATE : Unfortunately none of answers are correct because I don't need a repository-located hook. I need a hook on my local computer to prevent me from using --force flag when pushing to remote.

The receive.denyNonFastForwards config option can do what you want.

 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.

Set this in your personal git configuration with

git config --global receive.denyNonFastForwards true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM