Delete Git Branches

Below are some steps to clean branches from the git repository to remove the clutter.

Delete a Local branch

To delete the local branch in Git using the command, we can use one of the followings:

# git branch -d branch_name
# git branch -D branch_name

As you can see above, we have 2 different arguments, one with small case d and one with capital case D.

The -d option stands for –delete, which would delete the local branch. The -D option stands for –delete –force, which deletes the branch even if there are uncommitted changes.

Delete a remote branch

To delete a remote branch, we can use the following command:

# git push {remote_name} –delete {branch_name}

Above command can also be used if we want to delete git tags.

You can get more commands from this Git Cheat Sheet.

Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.