Bug 550730 - Provide the ability to force the creation of a branch even if it already exists (git branch --force <branchname>)
Summary: Provide the ability to force the creation of a branch even if it already exis...
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: 5.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-04 03:44 EDT by Michael Schnell CLA
Modified: 2019-09-05 05:04 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schnell CLA 2019-09-04 03:44:52 EDT
This is a feature request (for git branch --force <branchname>)

The EGit UI Dialog "Create Branch" should provide the ability to "--force" the branch creation, even if a branch with that name already exists. The current UI does not allow this and just refuses to create the branch.

If a user wants to force a branch to a specific commit using the current EGit, he needs to either delete the branch and re-create it or he needs to check it out and then move it to the desired commit (e.g. with a hard reset or use merge to perform a fast-forward).

In both cases the user needs to close the "Create Branch" Dialog and then perform time consuming actions.


-- My use case --

It happens quite often that I create a branch from a remote tracking branch in the history view. If I already created that branch some time ago it already exists and the dialog refuses to create the branch.

In my case the local branch points almost always to an ancestor commit of the remote-tracking branch, so there are no commits that aren't already in the history of the remote-tracking branch. What I want to archive in this case is to fast-forward the local branch to the remote-tacking branch and check out the current state. 

Using --force would allow me to do that. EGit could even be so smart to show me whether this would be equivalent to a fast-forward nor not.
Comment 1 Michael Keppler CLA 2019-09-05 02:27:32 EDT
For requirements it is always dangerous to describe the intended solution instead of the problem.

The suggested checkbox would require users to understand that there is a "force" option on command line git and what it does. Many egit users don't know _any_ command line usage of git (as I can tell from personal experience).

Therefore the UI should instead just provide an option saying something like "delete the existing local branch" before continuing with the checkout. That is something every user understands and which leads to the same desired result. Under the hood egit might then use the force option (if it exists in jgit, I don't know) or actually really delete the local branch.
Comment 2 Michael Schnell CLA 2019-09-05 05:04:00 EDT
Thank you for your feedback. I've adjusted the issue title.

It doesn't need to be a checkbox and the UI doesn't need to use the term "force". 

But it would be consistent with the other places that already support the equivalent to the command line "--force" option.

Create New Tag Dialog
  [ ] Force replace existing tag

Push Branch Dialog 
  [ ] Force override existing branch in remote if exists and has diverged


So a suggested solution would be a checkbox using the term "force" like

  [ ] Force replace existing branch


I agree with that most users do not know the command line git ;-) 
But I used the term --force here because I'm sure that the EGit/JGit developers know what I mean :-)