How to delete a branch in GIT

Gunschu Blog
2 min readMay 18, 2022

Deleting a branch should be simple, yes ?

Well for the most part it is. use this command and you should be done!

git branch -d mybranch

However here are some common issues you may come across.

Scenario

error: Cannot delete branch ‘custombranch’ checked out at ‘/Users/***/Documents/**/**’

This means you are mostly likely checked out into this branch that you are trying to delete.This could be through an embedded IDE terminal or your terminal or command app. In that case , first checkout a different branch. Then you are free to delete the branch you want.

git checkout mastergit branch -d mybranch

Scenario

error: the branch ‘custombranch’ is not fully merged. If you are sure you want to delete it

In this case use , git branch -D mybranch

If you are looking to delete a branch remotely , use

git push origin --delete custombranch

Scenario

error: error: unable to push to unqualified destination: custombranch The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@repository_name'

This just means that the branch list on remote versus local is out of sync.Most likely the remote branch is already deleted.

Use this command to sync the lists.

git fetch -p

--

--

Gunschu Blog

Gunschu is creating the world’s greatest coaching platform through groundbreaking tools, advice, knowledge and personal expertise.