In TortoiseGit, what is the equivalent of git branch -d (without the --force option)?

Viewed 138

How to delete a Git branch with TortoiseGit has been partially answered here. However it doesn't cover the --force option. How can I use TortoiseGit's delete branch feature without the --force option?

2 Answers

When you use the "Browse References Dialog" (Context menu: TortoiseGit → Browse Reference..., you might need to hold Shift while opening the context menu) for deleting local branches, TortoiseGit checks whether a specific branch is already merged into HEAD and presents a different confirmation dialog.

cf. TortoiseGit manual: https://tortoisegit.org/docs/tortoisegit/tgit-dug-browse-ref.html

Starting with TortoiseGit 2.5.6 before deletion of a local branch it is checked whether it was merged to HEAD and the result is displayed, so that you can decide whether to delete the branch or not.

TortoiseGit uses git.exe branch -D to delete branch if libgit2 is not employed to delete refs. And, there is no use case for -d option. See:

enter image description here

(From TortoiseGit 2.5.2 source code)

However, TortoiseGit usually asks user if they want to delete the branch. See:

enter image description here

Useful information: (from comment by @Fabien Bouleau)

Git with "-d" checks that the branch has been merged before deleting.
TortoiseGit shows an agnostic prompt, a confirmation to prevent a click by mistake.
But it does not preserve your work.

(If you deleted an unmerged branch, you can get it back by using Reflog dialog. Actually, get those commits back. :P )

Yes. TortoiseGit should do something for deleting unmerged branch.

Related