JoJo
JoJo

Reputation: 1447

what's difference about git branch -d <branchname> and git branch -D <branchname>

I an newer about git. after I merge my branch from another branch, I found something wrong. Now my status is I have commit these changes from merging, but not push into the origin/mybranch. So I just wanna delete my local branch. Then I use git branch -d mybranch. However, it failed. It told me that I cann't delete my local branch. After searching goolge, I found the command git branch -D mybranch, and used it to delete my branch successfully. So could anyone told the difference about these two commands ?

Upvotes: 2

Views: 4350

Answers (2)

michas
michas

Reputation: 26565

You can find the answer using git help branch. (Because it is regarding the git branch command.)

There you find:

-d
--delete

    Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream.
-D

    Delete a branch irrespective of its merged status.

Usually you do git branch -d. - If git complains, you should think again and if you are sure you do not need any commits from that branch anymore you can do git branch -D to delete it anyway.

Upvotes: 4

Joe Phillips
Joe Phillips

Reputation: 51200

The -D is a force-delete and the -d will provide a warning before deleting if the branch has not been merged into its upstream branch

Upvotes: 6

Related Questions