Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git have an "I am an idiot" switch to prevent push -f without a branch?

Tags:

git

I just did a

git push -f 

without including the branch I intended to push and git just blasted in everything to my repo. Fortunately we could piece together the old repo without to much trouble but it would be nice if I could change a setting in git to prevent -f all or make it so I have to do it explicitly.

Anyone aware of a setting I can change for this?

like image 419
matthewdaniel Avatar asked Nov 26 '25 02:11

matthewdaniel


1 Answers

You can setup a pre-receive hook on the remote repo, that can prevent force push. You can also ensure that force push can only be done if explicitly specifying a particular branch.

You can also setup your local repository to change the default behaviour of the git push so that it will push only the current branch:

For example, to default to pushing only the current branch to origin use git config remote.origin.push HEAD. Any valid (like the ones in the examples below) can be configured as the default for git push origin.

like image 150
manojlds Avatar answered Nov 28 '25 16:11

manojlds



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!