my git aliases: please = git force --with-lease

Christophe Colombier - Aug 10 '22 - - Dev Community

how many times did you face this ?

git push
Enter fullscreen mode Exit fullscreen mode

and it fails, and it's normal because git prevents you to update a branch while you would break everything

Some of you may do this, DO NOT !

git push --force
Enter fullscreen mode Exit fullscreen mode

it's dangerous as you can nuke someone else changes and mess the repository for everyone else than you.

Please note that git push tells you it will cause problem, and by using --force you are telling it, you don't care at all.

--force may be useful is some narrow, restricted and very rare situation, but on daily basis you don't want to use it.

Some others, more careful, are using this

git push --force-with-lease
Enter fullscreen mode Exit fullscreen mode

Read the following articles about --force-with-lease vs --force:

Some really careful (and using git version over 2.30) are using this

git push --force-with-lease --force-if-includes
Enter fullscreen mode Exit fullscreen mode

Here is an excellent article about --force-if-includes

The differences are really slightly, but they added it for good reasons.

ok, but then ?

There is unfortunately no git config to ask git to always uses --force-with-lease whenarticle

g changes.

one way to achieve it is to use an alias

[alias]
please = push --force-with-lease --force-if-includes
Enter fullscreen mode Exit fullscreen mode

So next time you will face an error with git push, you may ask very politely with git please alias

I'm not sure from where I got this alias, maybe a coworker.

By writing this post, I found a possible source article
https://www.freecodecamp.org/news/git-please-a182f28efeb5/

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .