how many times did you face this ?
git push
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
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
Read the following articles about --force-with-lease
vs --force
:
- https://stackoverflow.com/questions/52823692/git-push-force-with-lease-vs-force
- https://www.delftstack.com/howto/git/git-push-force-with-lease/
Some really careful (and using git version over 2.30) are using this
git push --force-with-lease --force-if-includes
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
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/