Knowledge - Details

How to Force Push to Git (push -f) in Visual Studio
Date Added: 1/13/2022

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.

Back to List