How to Delete a Local Git Branch?

The command to delete a local git branch has the following syntax:

git branch --delete <branch_name>

# or the shorter version
git branch -d <branch_name>

You can also force-delete a branch using the -D flag like so:

git branch -D <branch_name>

For example, to remove the local branch called "foo" you could use any of the following commands:

git branch --delete foo

# or the shorter version
git branch -d foo

# force-delete
git branch -D foo

Please note that these commands do not delete the remote branch. Deleting a remote branch is done in an entirely different way.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.