DEV Community

Cover image for How to delete a branch locally in Git?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to delete a branch locally in Git?

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Both ways of writing the command have the same effect.

Feel free to share if you found this useful 😃.


Top comments (0)