Search code examples
gitphpstorm

Is it possible to completely empty out the local list of branches for a remote repository?


For example, if you run git remote add repository and then git fetch repository it will populate all branches found on the repo. Is there a way to reset the list of branches to the same as when you initially added it, with none fetched?

PHPStorm by default lists every remote branch that has been fetched. This list has gotten rather long and I would like to remove listed branches without actually deleting them or the remote (so if I do want them back in the future it won't require me re-adding the repo).


Solution

  • Came up with the below solution to empty out the list of remote branches for a repo. Similar to Thomas' solution but still using entirely git to loop through and delete all remote branches:

    git branch -d -r $(git for-each-ref --format="%(refname:short)" refs/remotes/**repository**/)