thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

git: prune gone upstream branches

• 89 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Problem statement: Delete all local git branches whose upstream counterparts have already been merged (“gone” in git lingo).

Augment your ~/.gitconfig:

ini
[alias]
	prune-gone = !git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -D

Run git prune-gone. That’s it.

It lists all branches that are “gone” and deletes them.

I have another git alias ('world') to do all this sort of clean-up tasks at once:

ini
[alias]
    world = !git fetch --all && git remote prune origin && git prune-gone