1

When I run the command git branch -a I see a list of branches associated with a remote that no longer exists. ex:

remotes/does-not-exist/branch1
remotes/does-not-exist/branch2
remotes/origin/dev
remotes/origin/feature3

I want to remove the branches associated with does-not-exist from the list above. However if I run the command git remote prune does-not-exist I get the following error

conq: repository does not exist.
fatal: Could not read from remote repository.

How can I remove the branches associated with does-not-exist? Should I just delete the folder under .git/refs/remotes/?

Aaron Hoffman
  • 6,604
  • 8
  • 56
  • 61

4 Answers4

4

I merged a branch to the master using the GitLab web page.

On my local shell, the branch was still present

git branch -a
* 9-deploy
master   
remotes/origin/9-deploy   
remotes/origin/HEAD -> origin/master   
remotes/origin/master

Deleted the local branch with

git branch -d 9-deploy

Deleted the reference to the remote branch with

git fetch -p

Used the following reference to find commands

ddu
  • 41
  • 3
0

You should remove the remote, not branches. By this the branches will be deleted too. git remote remove does-not-exist.

kan
  • 28,279
  • 7
  • 71
  • 101
  • Thanks, @kan. I tried this, and perhaps I am just in a bad state, but this did not work for me. – Aaron Hoffman Nov 05 '15 at 19:52
  • I ran the command you provided, and then ran `git branch -a` again and I still saw the branches associated with the remote that no longer exists. – Aaron Hoffman Nov 06 '15 at 19:19
  • @AaronHoffman however, forced method to delete a reference is `git update-ref -d remotes/does-not-exist/branch1`. – kan Nov 06 '15 at 23:30
0

To delete remote branches, I run git push origin --delete <branch>. So in your case, you may run the following:

git push does-not-exist --delete branch1
git push does-not-exist --delete branch2

I hope this helps.

dlstadther
  • 395
  • 5
  • 15
  • Thanks, @dlstadther, however this is not working for me. The remote itself no longer exists, so attempting to delete the remote branch also does not exist. I get the same error as `git remote prune` above. – Aaron Hoffman Nov 05 '15 at 20:06
  • @AaronHoffman Have you found [this post](http://stackoverflow.com/questions/1072171/how-do-you-remove-an-invalid-remote-branch-reference-from-git)? – dlstadther Nov 05 '15 at 20:28
0

I had the same issue and was finally able to remove them using git branch -Dr does-not-exist/branch1.

sir-pinecone
  • 221
  • 2
  • 11