29
$ git branch
  develop
* feature/bug_76
  master
$ git branch -r
  origin/HEAD -> origin/master
  origin/develop
  origin/feature/implement_IBResponder
  origin/master
  origin/origin
  origin/sculptor_strategy

Locally, I am good. I want to delete all the crud on origin so I try:

$ git push origin :origin/sculptor_strategy
error: unable to delete 'origin/sculptor_strategy': remote ref does not exist
error: failed to push some refs to 'git@gitlab:pitbull.git'

What am I doing wrong?

(Wild Guess) Is some local cache of what's on origin stale?

ANSWER

It turned out to be a red-herring - the problem was, my local cache was stale, as I suspected. Both answers below will work fine.

kfmfe04
  • 14,936
  • 14
  • 74
  • 140
  • 5
    Have you tried `git push origin :sculptor_strategy`? – ConcurrentHashMap May 28 '13 at 07:59
  • y to both - same error message : `remote ref does not exist` – kfmfe04 May 28 '13 at 08:00
  • 1
    Relevant: http://stackoverflow.com/questions/14382999/so-many-unused-branches-how-to-cleanup/14384603#14384603 – mvp May 28 '13 at 08:01
  • possible duplicate of [How do I delete a Git branch both locally and in GitHub?](http://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-in-github) – David Schwartz May 28 '13 at 08:01
  • maybe the remote branch is already deleted? do `git fetch origin` and see. – Carlos Campderrós May 28 '13 at 08:03
  • @mvp +1 for a v.useful post - but does that mean I cannot cleanup/delete what's on origin? – kfmfe04 May 28 '13 at 08:03
  • @DavidSchwartz: it is not necessarily duplicate. OP may want to delete something that he shouldn't – mvp May 28 '13 at 08:04
  • 1
    Also possibly related: http://stackoverflow.com/questions/5751582/fetch-from-origin-with-deleted-remote-branches – pmr May 28 '13 at 08:04
  • @CarlosCampderrós Fetching alone will not help. He will need to fetch with the prune option, otherwise the deleted refs will not be deleted locally. – pmr May 28 '13 at 08:05
  • @pmr `git fetch -p` was the correct answer - add it as an answer and I will accept - TYVM. – kfmfe04 May 28 '13 at 08:07
  • WARNING: the link added above **This question may already have an answer here:** actually obfuscates the problem. Look at the answers below for clear solutions. – kfmfe04 May 28 '13 at 08:23

2 Answers2

40

You are probably not fetching with the prune option enabled. Use: git fetch --prune.

pmr
  • 58,701
  • 10
  • 113
  • 156
23

Use:

git remote prune origin

to drop references that are already removed remotely. Or:

git fetch -p origin

which does the same thing, or:

git remote update --prune

(I'm not really sure why there are so many ways to do this. They should all act the same, but in at least some versions of git, sometimes one will work and another won't, so if one form does not work it may help to try another.)

torek
  • 448,244
  • 59
  • 642
  • 775