#TIL 43 - Delete all remote branches except main

Jan 13, 2024 · Dung Huynh

What

Delete all remote branches except main from origin.

Why

Remote branches accumulate over time. Clean up to reduce clutter.

How

git branch -r | grep -v 'main' | sed 's/origin\///' | xargs -I {} git push origin --delete {}

Prune outdated tracking branches first:

git remote prune origin