How to Force Push to Git (push -f) in Visual Studio
Added: 1/12/2022 7:00 PM
By default, Visual Studio will not allow you to force push (git push -f) your local commit to the remote repo since it is a dangerous action that can cause data loss in the remote repo. To enable the ability despite the risk, in VS2022, go to Git > Settings > Git Global Settings, and enable "Enable push --force-with-lease". Now, when you click "Push" in VS, instead of just getting an error with a recommendation to Pull instead, the error messagebox will also include an option to Force Push. I suggest turning this setting back off when you're finished using it so you don't accidentally click it later.