Nicer git push with lease2019-04-28
I ran into this note of
git push --force randomly.
Typically, this command is very rude, especially when collaborating with others and you haven’t checked whether anyone else has committed to the remote shared repository.
This can occur when the commits you’ve made do not account for commits made by another person.
If you were to
git push --force after rebasing,
then the other person’s commits would be deleted.
git push --force-with-lease,
git will check whether the rest of your branch history is consistent with the
remote you’re pushing to.
If not, it will prompt you to pull in those new changes.
has an excellent example code through,
which has an example of Alice and Bob committing to the same remote and helped
me understand this feature1.
Things to share
Speaking of rebase from above, I’ve used this usually in a command line way, where I just type it out and be done with it.
I forgot there is an interactive way of this,
git add -i to add interactively.
git rebase -i HEAD~4
can be used to reword commits (press r in the next screen), among other things.
Random tidbit. This
--force-with-leasewas added in commit https://github.com/git/git/commit/28f5d176110d2ed768a0a49159993c7a02d8cb15 ↩