DEV Community

Cover image for 🍂 Remove gone git branches
All In Developer
All In Developer

Posted on Edited on Originally published at all1n.dev

🍂 Remove gone git branches

After a few weeks of merged pull requests, your local git branches pile up with no remote behind them anymore. Cleaning them up one by one gets old fast, so here’s how I do it with a single command.


👉 Continue reading on my blog: 🍂 Remove gone git branches

Top comments (5)

Collapse
 
graysonlang profile image
Grayson Lang • • Edited

Thanks, this is great! Minor tweak to use the --filter option to make sure we're not possibly matching on commit string contents (as unlikely as that may be):

[alias]
    gone = "!f() { git fetch --all --prune; git branch --format '%(refname:short) %(upstream:track)' | awk '/\\[gone\\]/{print $1}' | xargs git branch -D; }; f"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
chadidi profile image
Abdellah Chadidi •

Some WIP branches be like: you'll gonna miss me when i'm gone 😄.

Collapse
 
all1ndev profile image
All In Developer •

😀

Collapse
 
gaetanrdn profile image
Gaëtan Redin •

Great :-)

Collapse
 
louispineaushift profile image
louis-pineau-shift •

Great article ! But it seems that it is not working with the git config remote.origin.prune true enabled because it looks like that this config also remove the reference to the remote branch :/