Live data from Hacker News

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

spencer.wtf

211–220 of 273 posts

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

#211

What's wrong with just deleting the whole folder and clone repo and whatever branch you're interested in? In any case it's not an urgent thing. You don't have to do this mid-work, you can wait until you push most stuff and then rm && git clone. The only case in which this wouldn't work is when you have a ton of necessary local branches you can't even push to remote, which is a risk and anti-pattern per se.

because of my precious stash? but also the repo is huge, the clone takes 10 minutes? And all the other branches...

doesn't your precious stash deserve an external folder or remote branch, in any case? the local repo is always a risk, so many things can ruin it. also, you only need to clean up like once a year, it's by definition a rare operation. A ton of branches doesn't grow overnight.

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

#213
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.

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

#214
post #141

Earlier quoted context omitted.

Also, git's "master" branch is named after a master recording or master copy, the canonical original from which duplicates are made. There is literally no reason for it be offensive except for those who retroactively associate the word with slavery.

I'll change my default branches to main when Masterclass change their name to Mainclass

And mastering a subject is changed to maining it?

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

#217

Earlier quoted context omitted.

How to list those? Is there a flag for git branch to sort by recently modified? (not on my computer right now to check)

I do `gb` (probably "git branch" when I set that up) which apparently is an alias to `git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)' | tac`, displays a list with the latest changed branch at the bottom. Remove the `| tac` for the reverse order.

Yes, I run something like this (PowerShell borks out unless there are double quotes inside the single quotes) in a short script when I need to review available branches:

  git fetch --all --prune --quiet
  git log origin/main --date=format:%m%d%H%M --pretty=format:'%C(yellow)%ad-%h%C(auto)%d %s (%cn)' -n1 
  git log --tags --date=format:%m%d%H%M --pretty=format:'%C(yellow)%ad-%h%C(auto)%d %s (%cn)' -n1
  echo ''
  git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(color:yellow)%(committerdate:format:%m%d%H%M)-%(objectname:short) (%(color:green)%(refname:short)%(color:yellow)) %(color:white)%(contents:subject) (%(authorname))'
I include a [month][day][hour][minute]-[git hash] prefix as enough info to see when branches were last updated and grab them when I make a mistake creating the branch from the wrong parent or want to cherry-pick.

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

#219

"ciaclean" is a nice touch. I assume CIA stands for Clean It All.

"Clean It All, Clean" :P

At least someone got it, lol. "GNU is Not Unix" et al. ;)

Clean It All Clean also sounds like a 50s detergent slogan, so it's got that going for it.

Post reply on HN