Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push --force from IntelliJ IDEA

It seems that the force option was removed from the pushing dialog. I am currently using IntelliJ IDEA 13.1.1 and I cannot find any way how to push with force option. I tried to search the documentation and it seems that in version 10 the force option was still there. Do you maybe know how to push with force from IntelliJ IDEA?

like image 976
Jiri Peinlich Avatar asked Mar 28 '14 16:03

Jiri Peinlich


People also ask

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

How commit and push your code in Git using IntelliJ?

Right click -> Git -> Add. Commit files (Ctrl-K or VCS -> Git -> Commit) [Commit & push easier, but can also just Commit] If files not pushed in step above, VCS -> Git -> Push.


2 Answers

Since IntelliJ IDEA 14 update it's possible to enable a checkbox for exactly that, you first have to enable "Allow force push" in Settings->Version Control->Git.

2018 Update: To allow force push on master branch, look for "protected branches" in Git settings -> Then delete value "master".

like image 141
Alim Özdemir Avatar answered Sep 20 '22 20:09

Alim Özdemir


As far as issue 85773 is concerned, that option shouldn't be in the GUI yet (for IDEA 11-12 or 13+).
And it would be disabled when on the master branch.

That is why issue 76252 advocates to be able to type git commands in the git console: that way, you still have a way to execute the right command, without leaving the IDE.


Update November 2014, for IntelliJ 14 (won't be backported to 13):

To enable the feature user have to select "Allow force push" in Settings | Version Control | Git".

As some additional protection we've added a configuration option there to specify the list of "protected" branches, i.e. branches which are not allowed to be force pushed to.
The value is saved in .idea/vcs.xml and thus is shared among the team.


Update March 2018: the thread "Intellij 2018.1 force push" mentions:

When a protected branch is selected as a target for a push in the Push dialog, Force push option is disabled.

If you push to some other branch, Force Push option is available.

The Help page on Git settings details:

Protected branches

If you want to disable the ability to force push changes for certain branches, list them here (this is a team-shared parameter that is stored in .idea/vcs.xml).

You can list several branches separated by a semicolon, or supply branch patterns as the input is treated as a list of regular expressions.

So to have the ability to force push against master, you need to delete master from the list of protected branches.

like image 33
VonC Avatar answered Sep 17 '22 20:09

VonC