Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 3
    +1 for the remote version as well (but less needed as we have remote --prune). Also worth noting that thoose won't work with older git version Commented Jun 11, 2015 at 8:09
  • 7
    git config --global --add fetch.prune true to prune automatically on fetch or pull. Commented Dec 18, 2015 at 14:51
  • 5
    Mind you, prune is not the same as the remote clear. The remote clear actually deletes the remote branches that are fully merged with your current branch. Prune only cleans up your local registry of remote branches that are already deleted. Commented Jan 5, 2017 at 14:07
  • 1
    To delete all the origin remotes in one call, I used this: git branch -r --merged | grep -v '\*\|master\|develop' | grep '^\s*origin/' | sed 's/origin\///' | tr "\n" " " | xargs git push --delete origin Commented Oct 3, 2018 at 13:51
  • 1
    Note that you should be on the fully updated master branch when you run the remote one, otherwise you risk deleting the branch you're currently on from remote and losing some pull requests and such. Commented Jul 19, 2021 at 17:47