Tag Archives: git

How to delete a branch in git

Git Logo
Image by Jason Long CC BY 3.0

Git encourages branching but sometimes you need to do a clean up and delete merged or orphaned branches from your local and remote repositories. Here is the procedure from the command line.

To delete a branch locally:

git branch -d branchname

You may get an error like this one if the branch has not been merged yet:

error: The branch 'branchname' is not fully merged.
If you are sure you want to delete it, run 'git branch -D branchname'

This is a good reminder in case you are deleting something you should not be deleting.

To delete a branch remotely (e.g. on a GitHub repository):

git push origin --delete branchname