1

git branch -a shows

master
remotes/origin/master
remotes/upstream/bugfix/corrupted-deb
... (many more remotes/upstream branches)

The repository upstream no longer exists. How to delete the zombie branches remotes/upstream/bugfix/corrupted-deb etc for good?

File .git/config contains no more than

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@<myurl>
    fetch = +refs/heads/*:refs/remotes/origin/*

Any intentional reference to upstream is gone since long.

The command git remote prune origin [https://stackoverflow.com/questions/8766525] doesn't affect upstream. The obvious variant git remote prune upstream results in fatal: 'upstream' does not appear to be a git repository ...

Joachim W
  • 7,290
  • 5
  • 31
  • 59

2 Answers2

2

Try:

git update-ref -d refs/remotes/upstream/bugfix/corrupted-deb

Sometimes you may have a symbolic ref like:

remotes/origin/HEAD -> origin/master

To remove remotes/origin/HEAD, run:

git symbolic-ref -d refs/remotes/origin/HEAD

To remove all remotes/upstream, try:

git for-each-ref refs/remotes/upstream --format="%(refname)" | while read ref;do
    git update-ref -d ${ref}
done
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • Yes, `git update-ref -d refs/remotes/....` works. In reality, though, I have tons of dead upstream branches (I edited my question to say that). Any way to delete them all at once? – Joachim W Nov 15 '19 at 10:07
1

git branches -a is just telling you that you have a file locally in your .git folder (created through git fetch, at some point). Just remove it:

.git/refs/remotes/upstream/bugfix/corrupted-deb

To exemplify i created a small test project and created, manually, a file .git/refs/remotes/test/feature/mybranch pointing to the sha of a single commit i made.

Running git branch -a now yields:

/c/dev/remotetest (master)
$ git branch -a
* master
  remotes/test/feature/mybranch

After removing the file .git/refs/remotes/test/feature/mybranch running git branch -a now yields:

/c/dev/remotetest (master)
$ git branch -a
* master

/Martin

zrrbite
  • 1,180
  • 10
  • 22