6

Can some body please help me to understand what is the difference between following two git commands?

$ git branch -d testing

and

$ git branch -D testing

When should we use -D?

Mukesh
  • 7,630
  • 21
  • 105
  • 159
  • 1
    The differences between the two flags are explained in the [`git-branch` man page](http://git-scm.com/docs/git-branch). Have you had a look at it? – jub0bs Jul 02 '15 at 13:15

2 Answers2

8

git branch -d is for deleting branches that are fully merged in its upstream branch or to HEAD if you don't have a upstream for your branch. If the branch is not fully merged it will not perform the deletion.

git branch -D deletes the branch even if it's not merged.

crea1
  • 11,077
  • 3
  • 36
  • 46
4

In complement to the other answer: think of -D as -d --force. -d is the safe option, you probably want to teach your fingers to use this one. When -d refuses to delete the branch, make sure you know what you're doing, and then use -D.

Actually, -D sounds so much like -d --force that you can indeed use -d --force since Git 2.3.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65