git-commander icon indicating copy to clipboard operation
git-commander copied to clipboard

Allow Force Deletion of Branches

Open MichaelFoss opened this issue 2 years ago • 0 comments

When a branch is not fully merged, branch deletion is impossible within Git Commander.

Consider the following repo:

❯ mkdir git-repo
❯ cd git-repo
❯ git init
Initialized empty Git repository in ~/git-repo/.git/
❯ git checkout -b main
Switched to a new branch 'main'
❯ touch initial-commit
❯ git add --all
❯ git commit -m "Initial commit"
[main (root-commit) 431a8c2] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 initial-commit
❯ git branch
* main
❯ git checkout -b tmp
Switched to a new branch 'tmp'
❯ touch branch-file
❯ git add --all
❯ git commit -m "Branch commit"
[tmp 49ef858] Branch commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 branch-file
❯ git checkout main
Switched to branch 'main'

The resultant Git repo looks like this:

  * tmp
 /
* main

Trying to delete the branch results in an error, because the branch is not yet fully merged:

❯ git branch --delete tmp
error: The branch 'tmp' is not fully merged.
If you are sure you want to delete it, run 'git branch -D tmp'.
❯ git branch
* main
  tmp

In order to delete the unmerged branch, one must do a force delete:

❯ git branch --delete --force tmp
Deleted branch tmp (was 49ef858).
❯ git branch
* main

Git Commander does not allow for force deletion of branches. In the event that the user is requesting the deletion of a non-fully merged branch, Git Commander should provide a confirmation dialog stating that the branch is not fully merged. If the user cancels from the dialog, the deletion should do nothing (as it does today), but if the user confirms from the dialog, the deletion attempt should be re-executed forcefully (i.e. with the --force flag).

MichaelFoss avatar Jan 04 '23 12:01 MichaelFoss