logoalt Hacker News

I found a useful Git one liner buried in leaked CIA developer docs

575 pointsby spencerldixontoday at 2:03 PM203 commentsview on HN

Comments

spectaclepiecetoday at 8:31 PM

how is this a news item. LLMs figured this out for me two years ago

galbartoday at 2:22 PM

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

show 1 reply
tpoachertoday at 7:27 PM

grep + xargs ... in other words, we're finally back at good old standard svn workflows

Arch-TKtoday at 2:49 PM

Unfortunately doesn't work if the project you work on squashes everything :(

schifferntoday at 2:51 PM

"ciaclean" is a nice touch.

I assume CIA stands for Clean It All.

show 2 replies
fragmedetoday at 9:14 PM

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.

arduanikatoday at 6:39 PM

Trust Langley to neatly tie up all the loose ends.

locallosttoday at 7:37 PM

I've used this for about 10 years now. Pretty sure it was a widespread way of doing it before any CIA leak.

rickknowltontoday at 4:10 PM

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??
Svokatoday at 6:14 PM

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-merged
freecodyxtoday at 8:27 PM

i 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

devhousetoday at 3:47 PM

don't forget to fetch first

nivcmotoday at 7:12 PM

[dead]

bobjordantoday at 4:51 PM

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.

show 9 replies
bgfjhgghhhgtoday at 4:18 PM

[dead]

huflungdungtoday at 9:34 PM

[dead]

morissettetoday at 2:37 PM

[flagged]

show 1 reply