Top
Best
New

Posted by spencerldixon 11 hours ago

I found a useful Git one liner buried in leaked CIA developer docs(spencer.wtf)
585 points | 210 commentspage 3
rudnevr 5 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 5 hours ago|
because of my precious stash? but also the repo is huge, the clone takes 10 minutes? And all the other branches...
9dev 5 hours ago|||
> because of my precious stash?

you mean the… pile of shame?

rudnevr 4 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.
maerF0x0 9 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
andix 5 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!

gritzko 11 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 10 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 10 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.

renlo 5 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.

atomicUpdate 4 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.

coderpersson 9 hours ago||
`git trash`

https://github.com/henrikpersson/git-trash

I use this script with a quick overview to prevent accidentally deleting something important

kazinator 6 hours ago||
Or don't go crazy making branches in the first place.

Have a merge workflow which deletes the branch right there.

1a527dd5 11 hours ago||
I use

    #!/bin/sh
    
    git checkout main
    git fetch --prune
    git branch | grep -v main | xargs --no-run-if-empty git branch -D
    git pull
Save that next to your git binary, call it whatever you want. It's destructive on purpose.
nikeee 10 hours ago|
I use git-trim for that:

https://github.com/foriequal0/git-trim

Readme also explains why it's better than a bash-oneliner in some cases.

More comments...