Anytime you are replacing commits on the remote, you can't just push, you need to force push. Below I will explain how to force push from Visual Studio 2019 (both the new way and old way which includes VS 2017), and the command line. I'll start with the command line in order to explain the different ways you can force push:
git push --force # blow away this branch on the server and replace it with whatever commits are on my local branch
git push --force-with-lease # blow away this branch on the server and replace it with whatever commits are on my local branch, but only if there are no new commits on the branch that I haven't fetched yet
git push --force-if-includes # blow away this branch on the server and replace it with whatever commits are on my local branch, but only if I have the remote tip commit in my reflog. This is a relatively new option, and is described in more detail here.
I highly recommend using #2 most of the time, and that is also what Visual Studio does when you force push within VS. To enable force push in Visual Studio 2019, go to the main Git menu, choose Settings (or Tools menu, Options), select Source Control, then Git Global Settings:
![VS2019 Git Settings]()
Then check the box for "Enable push --force-with-lease":
![How to enable Force Push]()
Once you have enabled the setting, the next time you try to push and your branch has diverged, you will be presented with a new option:
![Force push option displayed]()
Clicking the "Force Push" button is identical to running the command line:
git push --force-with-lease
Note: The Git menu in VS2019 is new. If you don't see it, and you want to try it, you can enable it from Tools->Options, select Environment, Preview Features, then check the box for "New Git user experience":
![How to enable the new Git Menu]()
Similarly, if you have it checked and don't like it, unchecking that box will set Git up like how it used to be in Team Explorer in Visual Studio 2017.
If you don't have the Git menu enabled (or you are using VS 2017), then the force push setting can be found in Team Explorer, Settings, Git Global Settings, then check the box for "Enable push --force".
Note the --force you see on the screen is a typo in Team Explorer in both VS2019 and VS2017, it actually does --force-with-lease:
![enter image description here]()