I accidentally created a branch and pushed it to the origin. I created it out of another branch, but didn’t commit any changes, so it should be “identical” to the original branch.
I want to remove the branch, so I first removed it locally with:
git branch -d <branch_name>
and then I wanted to remove from the remote location with:
git push origin :<branch_name>
but this gave me the error:
error: unable to push to unqualified destination: 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. fatal: The remote end hung up unexpectedly
I found information about this error on another thread in StackOverflow (Cannot delete a remote branch created unintentionally) and on other sites (git: prune to remove old remote tracking branches), but the solution they propose:
git remote prune origin
does not work for me. The prunning command exits correctly, but I still see the branch when I git branch -r or git branch -a.
I have also tried git remote update and git fetch but that didn’t change anything.
How can I remove this branch from the list of branches?
Try
git fetch --prune origin.Otherwise you could manually remove the branch from your local repository and see if it comes back on
git fetch(in which case it wasn’t removed on the remote):