74

From within Visual Studio Code, is it possible to do a git push --force <repo> <branch> in some way?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Roger Lindholm
  • 741
  • 1
  • 5
  • 3

4 Answers4

101

Since 1.35 (May 2019), provided that Settings > Extensions > Git > Allow Force Push is set, the force push option is also visible in the Git menu (three dots, more actions), sub-menu "Pull, Push".

You must first enable it in settings:

settings

Git Menu

Force push now visible

Note: You needed, with 1.35, to restart VSCode (or at least "Reload (VSCode) windows") in order to see that new option.
With more recent version of VSCode (1.65, 2022), no need to reload/restart.

See issue 62020, closed with PR 62021.

As noted by CletusW in the comments:

Note also by default this uses the safer --force-with-lease option, also configurable in Settings > Extensions > Git, toward the bottom

I detailed --force-with-lease in "git push --force-with-lease vs. --force".

Timmmm
  • 88,195
  • 71
  • 364
  • 509
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note also by default this uses the safer --force-with-lease option, also configurable in Settings > Extensions > Git, toward the bottom. – CletusW Jun 05 '20 at 07:11
  • 1
    @CletusW THank you, good point. I have included your comment in the answer for more visibility. – VonC Jun 05 '20 at 07:43
  • I restarted vscode but still this option is not there. Edit - It was present in Pull, Push sub-menu. – Mayank Kataria Mar 10 '22 at 14:32
  • 1
    @MayankKataria It is not in mine either... because I did not activate first the setting "`Allow Force Push`": activate it, and you will see this option. – VonC Mar 10 '22 at 14:43
  • @VonC Yes I got it. Its not present in main menu now. We have to navigate to sub menu of 'Pull, Push' option. – Mayank Kataria Mar 10 '22 at 17:30
  • 1
    @MayankKataria I have edited the answer and updated the picture, showing the option in its current place as you mentioned. Thank you for the feedback. – VonC Mar 10 '22 at 19:14
21

It is now available after September 2018 v1.28 release. Check the release notes for more information: https://code.visualstudio.com/updates/v1_28#_push-force

enter image description here

EDIT: Thank @Kevin for the hint. If you can't find the option, you can change the VSCode settings as follows:

enter image description here

Nour
  • 5,252
  • 3
  • 41
  • 66
5

I also faced same issue where I couldn't find the option to do force push in vscode 1.40

Here is a screenshot to find the option in the setting

enter image description here

deerawan
  • 8,002
  • 5
  • 42
  • 51
0
  1. Open Visual Studio Code
  2. Go to File --> Open Folder and select your project folder
  3. Select Ctrl+` to open the terminal window
  4. Type git push --force <repo> <branch> in terminal window and hot enter
Mani
  • 1,471
  • 1
  • 13
  • 19