Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a 'ghost' remote branch in Git?

Tags:

git

When I

git branch -a | grep my_funny_branch

it gives

remotes/origin/my_funny_branch

But when I

git branch -d -r origin/my_funny_branch

it gives

error: remote branch 'origin/my_funny_branch' not found

and when I just

git pull origin master

I get

git pull origin master
From ssh://example.com/foo/bar
 * branch            master     -> FETCH_HEAD
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
error: bad ref for refs/remotes/origin/my_funny_branch
error: bad ref for refs/remotes/origin/my_funny_branch
Counting objects: 47339, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (16489/16489), done.
Writing objects: 100% (47339/47339), done.
Total 47339 (delta 30622), reused 47339 (delta 30622)
Rename from '.git/objects/pack/.tmp-7576-pack-15e7c5d209199f384b04dd820a8d625c658f7402.pack' to '.git/objects/pack/pack-15e7c5d209199f384b04dd820a8d625c658f7402.pack' failed. Should I try again? (y/n)

How do I delete that remote branch?

Thanks!

like image 286
Drew LeSueur Avatar asked Sep 11 '14 16:09

Drew LeSueur


1 Answers

This error message is interesting:

error: bad ref for refs/remotes/origin/my_funny_branch

Looking at the Git source code, that message appears when Git is processing the reflog for that ref. It's possible the log is broken in some way, preventing various operations on the ref from completing successfully.

After backing it up, try deleting the log for that ref:

rm -rf .git/logs/refs/remotes/origin/my_funny_branch

and then see if you can delete the branch.

like image 61
Richard Hansen Avatar answered Sep 29 '22 22:09

Richard Hansen