47

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?

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
serup
  • 3,676
  • 2
  • 30
  • 34

2 Answers2

73

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+ **

AutoTester213
  • 2,714
  • 2
  • 24
  • 48
  • 1
    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. – serup Aug 28 '17 at 08:08
  • 2
    Aggreed but, if you want to use it one some push you should just use command prompt for that specific push. – AutoTester213 Aug 28 '17 at 13:14
  • 20
    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! – Chad B Sep 05 '17 at 14:46
  • 5
    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. – spottedmahn Jan 05 '19 at 15:41
  • 1
    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. – Doug Knudsen Mar 31 '19 at 17:43
  • force push all you want, the sane approach is to manage force push privledges at the repository level – CervEd Jul 05 '21 at 10:24
29

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

Git Settings

Git force push settings

James Law
  • 6,067
  • 4
  • 36
  • 49