From within Visual Studio Code, is it possible to do a git push --force <repo> <branch>
in some way?
To enable force push, go to the top level menu, select “Git > Settings” and check the “Enable push --force” option.
To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).
Step 1: Create A GitHub Repository Enter a repository name and click on the Create repository button. Give a name to the repository and then click on the Create repository button. Once your repository is created, copy the web URL. This URL allows us to push code to this repository from VS Code.
As you do your work, Visual Studio keeps track of the file changes to your project in the Changes section of the Git Changes window. To stage changes when you're ready, select the + (plus) button on each file you want to stage, or right-click a file and then select Stage.
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
":
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
".
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With