How to delete a branch locally in Git?

Published January 2, 2021

To delete a branch locally in Git, you can use the git branch command and use a flag -D to set the command in deletion mode and pass the local name of the branch.

For example, consider a branch called new-features.

So the command looks like this,

git branch -D new-features

As you can see from the above command we have used the flag -D with the command which will instruct Git to delete a branch.

The flag doesn't have to be before the branch name, you can use the flag -D even after the branch name itself like this,

git branch new-features -D

Both ways of writing the command have the same effect.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter