I cannot remove a remote branch called origin/featureBranch. I guess it’s because the branch name starts with origin, but I am not sure:
$ git branch -r | grep featureBranch
origin/origin/featureBranch
$ git push origin :origin/featureBranch
error: unable to push to unqualified destination: origin/featureBranch
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@github.com:myCompany/my-repo.git'
UPDATE
$ git push origin :featureBranch gives the same error.
NOTE
In remote branch is origin/origin/myFeature, locally it is origin/myFeature.
I know what origin usually means, but in my case – this is part of name of the branch.
Github does not see this branch.
Could please anyone explain me what happens “behind the scene” and how can I remove this branch?
Try this:
You can always reference branches by their technical name under
refs/heads/.A branch is stored as a small text file under
.git/refs/. Local branches go under.git/refs/heads/, and remote branches under.git/refs/remotes/<remotename>/. A simple branch likemasterwill thus be found at.git/refs/heads/masterand.git/refs/remotes/origin/master, but your buggy branch will actually reside under.git/refs/heads/origin/featureBranch. It will not be confused with a remote branch on theoriginrepository because it’s not underrefs/remotes/origin/, but underrefs/heads/.On the remote server, the
origin/featureBranchbranch is local to the server, so it will be stored underrefs/heads/. When pushing to a given branch, you can identify it either by its name, or by its path, so if a name doesn’t work, just use the full path starting withrefs.How you ended up with this weird branch name? I can’t tell for sure, since I don’t know what you did, but I encountered the same problem when I used
git push --mirror, which pushes all the references, including remote ones, so it will create anorigin/branchnameas a local branch.