Git says remote ref does not exist when I delete remote branch

Viewed 135867

I ran git branch -a

* master
  remotes/origin/test
  remotes/origin/master

I want to delete my remote branch

I've tried

git push origin --delete remotes/origin/test

I got

error: unable to delete 'remotes/origin/test': remote ref does not exist

How is it not exist ?

I did a git branch -a, and I saw it listed.

Did I miss anything ?

13 Answers

I followed the solution by poke with a minor adjustment in the end. My steps follow
- git fetch --prune;
- git branch -a printing the following
    master
    branch
    remotes/origin/HEAD -> origin/master
    remotes/origin/master
    remotes/origin/branch (remote branch to remove)
- git push origin --delete branch.
Here, the branch to remove is not named as remotes/origin/branch but simply branch. And the branch is removed.

Given that the remote branch is remotes/origin/test you can use two ways:

git push origin --delete test

and

git branch -D -r origin/test

For me this worked $ ▶ git branch -D -r origin/mybranch

Details

$ ▶ git branch -a | grep mybranch remotes/origin/mybranch

$ ▶ git branch -r | grep mybranch origin/mybranch

$ ▶ git branch develop * feature/pre-deployment

$ ▶ git push origin --delete mybranch error: unable to delete 'mybranch': remote ref does not exist error: failed to push some refs to 'git@10.102.100.38:config/myrepo.git'

$ ▶ git branch -D -r origin/mybranch Deleted remote branch origin/mybranch (was 62c7421).

$ ▶ git branch -a | grep mybranch

$ ▶ git branch -r | grep mybranch

This should help:

  1. git fetch
  2. git push origin --delete branchName

For windows

git branch --remotes| %{ $_.Trim().Split("/")[1] }| ?{ $_ -ne 'master' } | | ?{ $_ -ne 'otherBranch' } | %{ git push origin --delete $_ }
Related