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

- 31,714
- 9
- 78
- 100

- 741
- 1
- 5
- 3
4 Answers
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:
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 inSettings > Extensions > Git
, toward the bottom
I detailed --force-with-lease
in "git push --force-with-lease
vs. --force
".
-
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
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
EDIT: Thank @Kevin for the hint. If you can't find the option, you can change the VSCode settings as follows:

- 5,252
- 3
- 41
- 66
-
13If you don't find this option: Settings > Extensions > Git > Allow Force Push – Kevin Robatel Feb 28 '19 at 07:11
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

- 8,002
- 5
- 42
- 51
-
this is the same with adding `"git.allowForcePush": true,` to `setting.json` – vanduc1102 May 09 '21 at 06:05
- Open Visual Studio Code
- Go to File --> Open Folder and select your project folder
- Select Ctrl+` to open the terminal window
- Type
git push --force <repo> <branch>
in terminal window and hot enter

- 1,471
- 1
- 13
- 19
-
2this actually helped me while other answer (even from other questions) didn't – Tinaira Feb 21 '19 at 20:13