How to delete all deleted tracking branches that still exist on the remote computer but no longer in my fetch refspec

I recently reorganized my refspec remote.origin.fetch and now only retrieve a small subset of the branches from the remote. However, git branch -a shows me many remote branches that I selected earlier, although they are no longer loaded. Using git prune will NOT help, as these remote tracking branches exist on the remote computer.

+4
source share
2 answers

The answer from robrich has good advice: you can simply delete each branch of the remote tracking (or even the remote one), and then use git fetch to grab only the ones you want now from scratch.

If you try to delete the remote all together, you can back up your .git / config file so that when adding remote access later you can choose the setting for the remote source from the backup.

However, deleting the remote does not delete the remote tracking branches for me. Maybe my local repo is bad. For those who have the same problem, I ended up:

 # This deletes all remote tracking branches for all remotes. So be careful if you have multiple remotes. git branch -r | xargs -L 1 git branch -rD 

In addition, I have many tags from the remote, which slows down. I did it too:

 # Be careful! This deletes EVERY tag! git tag | xargs -L 1 git tag -d 

You might want to tweak git fetch so that you don’t have to return all those tags next time, which is beyond the scope of this question.

+4
source

You can delete the remote and re-add it, and then remote.origin.fetch . He hits the ant hill with a hammer, but he will do his job. You still need to remove the local branches (if any), but it's just git branch -D theOffendingBranchName .

Edit: If you feel adventurous, you can go robbery through .git/refs/ delete files you don’t need. First backup your .git folder if - in case the cropping is very wrong.

+1
source

All Articles