The git plugin in oh-my-zsh has an alias for this: gbda
It also has one for squash-merged branches: gbds
Very useful I've been using them for years
grep + xargs ... in other words, we're finally back at good old standard svn workflows
Unfortunately doesn't work if the project you work on squashes everything :(
"ciaclean" is a nice touch.
I assume CIA stands for Clean It All.
I want to point out explicitly that .git config supports aliases, so in .gitconfig put an [alias] section, and in that you can put ciaclean = "!alias ciaclean='git branch --merged origin/main | grep -vE "^\s(*|main|develop)" | xargs -n 1 git branch -d'"
so then it's `git ciaclean` and not bare `ciaclean` which imo is cleaner.
Trust Langley to neatly tie up all the loose ends.
I've used this for about 10 years now. Pretty sure it was a widespread way of doing it before any CIA leak.
honestly my go to is kind of similar, but I prefer using --format vs. straight grep. just feels like the plumbing is cleaner out of the box:
git branch --merged origin/main --format="%(refname:short)" \ | grep -vE "^(main|develop)$" \ | xargs -r git branch -d
that said... pretty hilarious a dev was just like "uhh yeah ciaclean..." curious what... other aliases they might have??I work with GitHub, so this oneliner relly helps me out. It also doesn't rely on grep, since --format have all you need:
git branch --format '%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' --omit-empty | xargs --verbose -r git branch -D
It deletes all the branches for which remotes were deleted. GitHub deletes branches after PR was merged. I alias it to delete-mergedi once used ai to generate a command doing the exact same thing.
git branch -vv | grep ': gone\]' | awk '{print $1}' | xargs -n 1 git branch -D
don't forget to fetch first
[dead]
I use `master` in all my repos because I've been using it since forever and it never has once occurred to me "oh shit I better change it to `main` this time in case `master` may offend somebody some day. Unfortunately, that's the last thing on my mind when I'm in programming mode. Now that everything is `master`, maybe it is just a simple git command to change it to `main`. But, my fear is it'll subtly break something and I just don't have enough hours left in my life to accept yet unknown risk that it'll cost me even more hours, just to make some random sensitive developer not get offended one day.
[dead]
[dead]
how is this a news item. LLMs figured this out for me two years ago