Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to git push --force in vscode?

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

like image 405
Roger Lindholm Avatar asked Mar 06 '17 21:03

Roger Lindholm


People also ask

How do I force a git push VS Code?

To enable force push, go to the top level menu, select “Git > Settings” and check the “Enable push --force” option.

Can you force a git push?

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).

Can VS Code push to github?

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.

How do I push changes in Visual Studio 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.


3 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":

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".

like image 62
VonC Avatar answered Oct 10 '22 22:10

VonC


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

like image 34
Nour Avatar answered Oct 10 '22 21:10

Nour


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

like image 5
deerawan Avatar answered Oct 10 '22 21:10

deerawan