push –force-with-lease by default

There currently is no way to configure git to always use force-with-lease instead of force. As such the next best available option is, as so often, to create an alias which serves this purpose.

EDIT This is still true in May 2022. But git 2.30 added an additional option force-if-includes which makes force-with-lease even safer; checkout this in-depth answer if you want to understand the reasoning.

Create an alias

To create an alias one would use git config --global alias.<alias-name> <command>, in our case I would suggest something similar to this.

git config --global alias.pushfwl "push --force-with-lease"

This will create an entry in your global .gitconfig file (which you can usually find in your home directory). After this you can use git pushfwl to force-with-lease.

Get your hands dirty

Alternatively you could decide to implement this feature yourself! If you aren’t sure where to start, you might want to take a look at the documentation directory in the git repository. Here you can find the coding guidelines and information on how to submit patches.

You can find all these links and more on the official community page.

Leave a Comment