--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
Added a link from the Linux section to Git Pro's instructions on storing git credentials with git. This provides some important elaboration on and alternatives to the instructions provided in the existing GitHub article.
Runners set up environment variables corresponding to the runner
context's properties. The runner context documents the runner.os,
runner.temp, and runner.tool_cache properties, so document these
three as supported environment variables similarly. The tool_cache
property value is not documented as being used for GitHub AE (see
context-and-expression-syntax-for-github-actions.md), so just leave
$RUNNER_TOOL_CACHE undocumented in this case.
* replace deprecated flag with new flag
* rework liquid versioning in article
* update flag descriptions to latest
* fix table formatting
* more table formatting
* Apply suggestions from code review
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
* address latest review comments
* version new flag for GHES 3.1+ only
* fix list numbeting
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>