how to make git push origin --force ; in Visual Studio Team Explorer
Asked Answered
P

2

48

I recently had an issue where I had to disregard my last commit, so on the command line I did following:

git push origin --force

this works fine, however I normally make my push/pulls from inside Visual Studio Team Explorer, however I could not find out how to --force a push from there

Is it possible or can it only be done from command line?

Placenta answered 25/8, 2017 at 10:26 Comment(0)
A
78

You can enable --force without using command prompt in visual studio 2017 as follows Open team explorer.

Team Explorer>Settings>Git>Global Settings

check the enable push --force checkbox and that should do the trick like so Check box

For more info check out this link

PS. **This feature is only available in visual studio 2017+ **

Aretina answered 25/8, 2017 at 10:36 Comment(6)
Yes but this is then done on the project all the time - what I was looking for was a way to only do it on some push, afterall using --force is not something which should be done unless you really know what your a doing.Placenta
Aggreed but, if you want to use it one some push you should just use command prompt for that specific push.Aretina
Enabling that checkbox does not do push --force all the time. If enabled, VS will check to see if a force push is necessary based on the state of the remote tracking branches. If it detects that a force is necessary, it will prompt you to be sure that is your intention. It will then do "git push --force-with-lease" in order to be careful in case anyone else had pushed to that remote branch since your last fetch. Hope this helps!Accident
After enabling, you still can't push from the Synchronization section in Team Explorer, you have to go to the Branches section and right click the branch and push from there.Amy
In addition to pushing from the Branches section, you can also "Push" from the branches drop-down in bottom right and you will be prompted if "force" is enabled.Wardell
force push all you want, the sane approach is to manage force push privledges at the repository levelAmmonal
P
33

It's now (as of VS2019) in Settings -> Source Control -> Git Global Settings:

Git Settings

Git force push settings

Parmentier answered 13/4, 2021 at 16:54 Comment(2)
Above is also valid for Visual Studio 2022.Sadi
then go ahead and push. A dialogue box appears, with a button to force push. Use that to overwriteBlowhole

© 2022 - 2024 — McMap. All rights reserved.