When deleting remote git branch "error: unable to push to unqualified destination"

Git

Git Problem Overview


I'm trying to delete a remote git branch with

git push origin :my_remote_branch

and getting:

error: unable to push to unqualified destination: my_remote_branch
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 '[email protected]:/myrepo'

these are my current branches

git branch -a
* develop
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/my_remote_branch

git branch -r --merged
  origin/HEAD -> origin/master
  origin/develop
  origin/master

Any ideas on how I can get rid of this branch would be appreciated.

Git Solutions


Solution 1 - Git

The fact that refs/remotes/origin/my_remote_branch exists in your local repository does not imply refs/heads/my_remote_branch exists in the origin remote repository.

Do git fetch -p origin to make refs/remotes/origin/my_remote_branch go away if it's already deleted in origin. The -p option tells fetch to delete any tracking branches that no longer exist in the corresponding remotes; by default they are kept around.

Solution 2 - Git

Found question https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches and this did the trick

git branch -r -d origin/my_remote_branch

Solution 3 - Git

I ran across this when trying to delete a remote branch that had already been deleted. All that was needed was a prune:

git remote prune origin

Solution 4 - Git

Try following two options to delete remote branch forcibly

Option 1

get push origin --delete <branchName>

Option 2

git fetch -p origin
git branch -r -d origin/<branchName>

Solution 5 - Git

git branch -r -d origin/my_remote_branch

was not enough for me. Before I had to go to server and work with git directory directly (which is dangerous and ugly) to remove the branch:

ssh mygitserver
su - git
cd /home/git/repositories/my_remote_branch.git/
git  --git-dir=. --work-tree=/tmp/ branch -D my_remote_branch

Solution 6 - Git

For me the problem was, that this was my default branch on github. I changed default branch, then delete operation was succeeded.

Hope it helps to someone

Solution 7 - Git

I have the similar problem. First went to this discussion, however I couldn't solve the problem until I saw https://stackoverflow.com/a/32147743/4209849.

which simply add a tip on distinguishing origin/my-branch-name and my-branch-name.

To be specific, I should use:

git push origin :my_remote_branch

instead of

git push origin :origin/my_remote_branch

This solved my problem at least, hope it would help others as well.

Solution 8 - Git

Had this same issue, I manually edited my ./.git/config file to include:

[branch "branchName"]
remote = origin
merge = refs/heads/branchName

Which resulted into: error: src refspec branchName matches more than one. This I fixed by running $git tag -d branchName. After which I was able to push the new branch to upstream.

Solution 9 - Git

This worked for me: I created the remote branch on github UI and then pushed my local branch which had the same name to it. Try it in case other ways dont work. Other way would be creating a new branch locally and pushing an empty branch and later cherry-pick your commit and push again to your remote.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHugoView Question on Stackoverflow
Solution 1 - GitJan HudecView Answer on Stackoverflow
Solution 2 - GitHugoView Answer on Stackoverflow
Solution 3 - GitMatthewView Answer on Stackoverflow
Solution 4 - GitPawan MaheshwariView Answer on Stackoverflow
Solution 5 - GitpevikView Answer on Stackoverflow
Solution 6 - GitVlad PulichevView Answer on Stackoverflow
Solution 7 - GitKangqiao ZhaoView Answer on Stackoverflow
Solution 8 - GitKaweesi JosephView Answer on Stackoverflow
Solution 9 - GitNutanView Answer on Stackoverflow