Top
Best
New

Posted by spencerldixon 10 hours ago

I found a useful Git one liner buried in leaked CIA developer docs(spencer.wtf)
562 points | 199 commentspage 2
kccqzy 3 hours ago|
Why not just git dmb? https://manpages.debian.org/testing/git-delete-merged-branch...
rudnevr 3 hours ago||
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.

efficax 3 hours ago|
because of my precious stash? but also the repo is huge, the clone takes 10 minutes? And all the other branches...
9dev 3 hours ago|||
> because of my precious stash?

you mean the… pile of shame?

rudnevr 3 hours ago|||
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.
atomicUpdate 2 hours ago||
This is the same thing as `git rebase-update`, available in Chrome's `depot_tools`, which deletes merged branches.

Beyond that, this is just OP learning how `xargs` works.

EricRiese 8 hours ago||
Much more complicated than necessary. I just use

git branch | xargs git branch -d

Don't quote me, that's off the top of my head.

It won't delete unmerged branches by default. The line with the marker for the current branch throws an error but it does no harm. And I just run it with `develop` checked out. If I delete develop by accident I can recreate it from origin/develop.

Sometimes I intentionally delete develop if my develop branch is far behind the feature branch I'm on. If I don't and I have to switch to a really old develop and pull before merging in my feature branch, it creates unnecessary churn on my files and makes my IDE waste time trying to build the obsolete stuff. And depending how obsolete it is and what files have changed, it can be disruptive to the IDE.

Cherub0774 9 hours ago||
We all have something similar, it seems! I stole mine from https://stackoverflow.com/questions/7726949/remove-tracking-....

I also set mine up to run on `git checkout master` so that I don't really have to think about it too hard -- it just runs automagically. `gcm` has now become muscle memory for me.

  alias gcm=$'git checkout master || git checkout main && git pull && git remote prune origin && git branch -vv | grep \': gone]\'|  grep -v "\*" | awk \'{ print $1; }\' | xargs -r git branch -D'
masklinn 8 hours ago|
Same using a git alias rather than shell, and without the network bits, it just cleans up branches which have an upstream that has been deleted:

    '!f() { git branch --format '%(refname:short) %(upstream:track,nobracket)'  | awk '$2~/^gone$/{print $1}'  | xargs git branch -D; }; f'
andix 3 hours ago||
I sometimes convert old branches to tags. So they don't show up in the list of branches, but I never lose any branches by accident.

All those "merged" workflows only work, if you actually merge the branches. It doesn't work with a squash merge workflow.

edit: I delegate this task to a coding agent. I'm really bad at bash commands. yolo!

renlo 3 hours ago||
I use this tool, which allows one to select the branches to delete instead of just deleting everything: https://github.com/stefanwille/git-branch-delete

Unfortunately its name makes it hard to search for and find.

d0liver 9 hours ago||
IIRC, you can do git branch -D $(git branch) and git will refuse to delete your current branch. Kind of the lazy way. I never work off of master/main, and usually when I need to look at them I checkout the remote branches instead.
maerF0x0 8 hours ago||

    DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')

    git branch --merged "origin/$DEFAULT_BRANCH" \
      | grep -vE "^\s*(\*|$DEFAULT_BRANCH)" \
      | xargs -r -n 1 git branch -d
This is the version I'd want in my $EMPLOYER's codebase that has a mix of default branches
gritzko 9 hours ago|
Speaking of user friendliness of git UI. I am working on a revision control system that (ideally) should be as user friendly as Ctrl+S Ctrl+Z in most common cases. Spent almost a week on design docs, looking for feedback (so far it was very valuable, btw)

https://replicated.wiki/blog/partII.html#navigating-the-hist...

oniony 9 hours ago|
Have you tried Jujutsu? If you want to make a better VCS, your baseline should be that, in my opinion, because it already deals with a lot of the Git pain points whilst be able to read and publish to Git repositories.
gritzko 8 hours ago||
The idea of using git as a blob storage and building entire new machinery on top is definitely a worthy one. At this point though, the de-facto baseline is no doubt git. If git as a store withstands the abuse of jj and jj becomes the industry standard, then I would agree with you. Also, at that point they may drop git backend entirely just because of price/performance discrepancy. git is overweight for what it does, if they make it do only the bottom 20%, then things will get funny.

Still, many oddities of git are inevitable due to its underlying storage model, so it makes sense to explore other models too.

More comments...