3

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,399
  • 20
  • 103
  • 152
  • 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

5

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
  • 9,209
  • 3
  • 34
  • 41
3

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
  • 13,111
  • 3
  • 36
  • 62