--force-with-lease is a safer and more recommended approach than --force
force overwrites a remote branch with your local branch.
--force-with-lease is a safer option that will not overwrite any work on the remote branch if more commits were added to the remote branch (by another team-member or coworker or what have you). It ensures you do not overwrite someone elses work by force pushing.
I think your general idea surrounding the command is correct. If the remote branch has the same value as the remote branch on your local machine- you will overwrite remote. If it doesn't have the same value- it indicates a change that someone else made to the remote branch while you were working on your code and thus will not overwrite any code. Obviously if there are additional commits in remote then the values won't be the same.
I just think of --force-with-lease as the option to use when I want to make sure I don't overwrite any teammates code. A lot of teams at my company use --force-with-lease as the default option for a fail-safe. Its unnecessary in most circumstances but will save you lots of headache if you happen to overwrite something that another person contributed to remote.
I'm sure you looked at the docs but there might be some more wordy explanation contained in here:
Read more : https://stackoverflow.com/questions/52823692/git-push-force-with-lease-vs-force
* Rename map topic
* Delete map topic
* Rename map topic
* Add redirect
* Remove last two map topics
* Move article on adding a remote into a long-form guide
* Move article on changing a remote's URL
* Move articles on renaming and removing remotes
* Move remote URL article
* Fix typo
* Remove category index file
* Move a few articles to the new category
* Move a few more files
* Move managing remote repos article
* Move the rest of the getting started with git map topic
* Move the first half of the using git map topic
* Move the rest of the articles and 🔥 the directory
* Fix failing test
* Remove Using Git from product index
* Apply suggestions from code review
Co-authored-by: Laura Coursen <lecoursen@github.com>
* Apply suggestions from code review
Co-authored-by: Laura Coursen <lecoursen@github.com>
* Run script/new-versioning/update-not-fpt-conditionals.js
* Fix a few things
* Remove outdated versioning
* Fix broken link
Co-authored-by: jmarlena <6732600+jmarlena@users.noreply.github.com>
* Add back changes from prior to purge
* Manually fix some invalid Liquid
* Updoot render-content
* Improve test messages to show correct output
* Run el scripto
* Pass the remaining test