| ▲ | I found a useful Git one liner buried in leaked CIA developer docs(spencer.wtf) |
| 128 points by spencerldixon an hour ago | 68 comments |
| |
|
| ▲ | lloeki 44 minutes ago | parent | next [-] |
| I've had essentially that - if a bit fancier to accept an optional argument as well as handle common "mainline" branch names - aliased as `git lint` for a while: [alias]
lint = !git branch --merged ${1-} | grep -v -E -e '^[*]?[ ]*(main|master|[0-9]+[.]([0-9]+|x)-stable)$' -e '^[*][ ]+' | xargs -r -n 1 git branch --delete
so: git pull --prune && git lint
sits very high in my history stats |
|
| ▲ | whazor an hour ago | parent | prev | next [-] |
| I currently have a TUI addiction. Each time I want something to be easier, I open claude-code and ask for a TUI. Now I have a git worktree manager where I can add/rebase/delete. As TUI library I use Textual which claude handles quite well, especially as it can test-run quite some Python code. |
| |
| ▲ | eulers_secret 19 minutes ago | parent | next [-] | | Tig is a nice and long-maintained git tui you might enjoy, then! If nothing else maybe for inspiration | |
| ▲ | firesteelrain an hour ago | parent | prev | next [-] | | Can you explain TUI? I have never heard this before | | |
| ▲ | GCUMstlyHarmls 35 minutes ago | parent | next [-] | | Eg: lazygit https://github.com/jesseduffield/lazygit?tab=readme-ov-file#... https://github.com/sxyazi/yazi https://github.com/darrenburns/posting or I guess Vim would be a prominent example. Peoples definitions will be on a gradient, but its somewhere between CLI (type into a terminal to use) and GUI (use your mouse in a windowing system), TUI runs in your terminal like a CLI but probably supports "graphical widgets" like buttons, bars, hotkeys, panes, etc. | | | |
| ▲ | Bjartr 42 minutes ago | parent | prev | next [-] | | Terminal User Interface, contrasting with a Graphical User Interface (GUI). Most often applied to programs that use the terminal as a pseudo-graphical canvas that they draw on with characters to provide an interactive page that can be navigated around with the keyboard. Really, they're just a GUI drawn with Unicode instead of drawing primitives. Like many restrictions, limiting oneself to just a fixed grid of colored Unicode characters for drawing lends itself to more creative solutions to problems. Some people prefer such UIs, some people don't. | | |
| ▲ | criddell 7 minutes ago | parent | next [-] | | > an interactive page that can be navigated around with the keyboard Or mouse / trackpad. I really haven't seen anything better for making TUIs than Borland's Turbo Vision framework from 35ish years ago. | |
| ▲ | Muvasa 21 minutes ago | parent | prev [-] | | I prefer tui's for two reasons.
1. Very used to vi keybindings
2. I like low resources software. I love the ability to open the software in less than a second in a second do what I needed using vi motions. And close it less than a second. Some people will be like you save two seconds trying to do something simple. You lose more time building the tool than you will use it in your life. It's not about saving time. It's about eliminating the mental toll from having to context switch(i know it sounds ai, reading so much ai text has gotten to me) |
| |
| ▲ | ses1984 an hour ago | parent | prev | next [-] | | Terminal UI. | |
| ▲ | booleandilemma 19 minutes ago | parent | prev | next [-] | | It's definitely an acronym that got popular in the last year or so, though I'm sure there are people out there who will pretend otherwise. I've been in the industry 15+ years now and never heard it before. Previously it was just UI, GUI, or CLI. | |
| ▲ | KPGv2 35 minutes ago | parent | prev [-] | | it's the name gen Z and gen alpha puppyn00bs have given to what us old heads have always called CLIs on tik too young folks are always discovering "revolutionary" things and giving them names, ignoring they're either super mundane, or already have a name on one hand, i absolutely LOVE the passion for discovery and invention on the other hand, if you're 19yo you probably didn't discover something revolutionary (Edit: I've seen some people online suggest a CLI is only when you manually type the command yourself, while a TUI incorporates text-based graphical elements, but that's something invented by young people; everything before GUIs was called a CLI until pretty recently. A terminal is /literally/ a command-line interface.) | | |
| ▲ | TarqDirtyToMe 25 minutes ago | parent | next [-] | | They aren’t the same thing. TUI refers to interactive ncurses-like interfaces. Vim has a TUI, ls does not I’m fairly certain this terminology has been around since at least the early aughts. | |
| ▲ | cristoperb 10 minutes ago | parent | prev | next [-] | | I don't know when the term became widespread for gui-style terminal programs, but the wikipedia entry has existed for more than 20 years so I think it is an older term than you imply. https://en.wikipedia.org/w/index.php?title=Text-based_user_i... | |
| ▲ | philiplu 17 minutes ago | parent | prev [-] | | Sorry, but this 65 yo grey-beard disagrees. A TUI to me, back in the 80s/90s, was something that ran in the terminal and was almost always ncurses-based. This was back when I was still using ADM-3A serial terminals, none of that new-fangled PCs stuff. |
|
| |
| ▲ | rw_panic0_0 24 minutes ago | parent | prev | next [-] | | how do you trust the code claude wrote? don't you get anxiety "what if there's an error in tui code and it would mess up my git repo"? | | |
| ▲ | sclangdon 19 minutes ago | parent [-] | | Isn't it this case no matter who wrote the code? How do you ever run anything if you're worried about bugs? | | |
| ▲ | phailhaus 17 minutes ago | parent [-] | | When I write the code myself, I'm not worried that I snuck a `git reset --hard` somewhere. |
|
| |
| ▲ | Trufa an hour ago | parent | prev | next [-] | | The amount of little tools I'm creating for myself is incredible, 4.6 seems like it can properly one/two shot it now without my attention. Did you open source that one? I was thinking of this exact same thing but wanted to think a little about how to share deps, i.e. if I do quick worktree to try a branch I don't wanna npm i that takes forever. Also, if you share it with me, there's obviously no expectations, even it's a half backed vibecoded mess. | | | |
| ▲ | hattmall 43 minutes ago | parent | prev | next [-] | | What are some examples of useful TUI you made? I'm generally opposed to the concept | |
| ▲ | lionkor an hour ago | parent | prev [-] | | That sounds like a complete waste of time and tokens to me, what is the benefit? So each time you do something, you let Claude one shot a tui? This seems like a waste of compute and your time | | |
| ▲ | htnthrow11220 an hour ago | parent | next [-] | | They said each time they want something to be easier, not each time they do something. And they didn’t mention it has to be one-shot. You might have read too quickly and you’ve responded to something that didn’t actually exist. | |
| ▲ | bmacho 40 minutes ago | parent | prev | next [-] | | Now that I think about it, if Claude can put most useful functions in a TUI and make them discoverable (show them in a list), than this could be better than asking for one-liners (and forgetting them) every single time. Maybe I'll try using small TUI too. | |
| ▲ | MarsIronPI an hour ago | parent | prev | next [-] | | On the contrary. Once these tools exist they exist forever, independently of Claude or a Claude Code subscription. IMO this is the best way to use AI for personal use. | |
| ▲ | duneisagoodbook an hour ago | parent | prev [-] | | yeah! they should focus on more productive pursuits, like telling people online what to do with their time and resources. | | |
|
|
|
| ▲ | Cherub0774 24 minutes ago | parent | prev | next [-] |
| 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 5 minutes ago | parent [-] | | 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'
|
|
|
| ▲ | password4321 7 minutes ago | parent | prev | next [-] |
| I don't delete branches, I just work with the top several most recently modified. |
| |
| ▲ | the_real_cher 3 minutes ago | parent [-] | | How to list those? Is there a flag for git branch to sort by recently modified? (not on my computer right now to check) |
|
|
| ▲ | arusahni an hour ago | parent | prev | next [-] |
| I use this alias: prune-local = "!git fetch -p && for branch in $(git branch -vv | awk '/: gone]/{if ($1!=\"\*\") print $1}'); do git branch -d $branch; done"
1. Fetch the latest from my remote, removing any remote tracking branches that no longer exist2. Enumerate local branches, selecting each that has been marked as no longer having a remote version (ignoring the current branch) 3. Delete the local branch safely |
|
| ▲ | ihsoy 14 minutes ago | parent | prev | next [-] |
| Dont most git instances, like github, delete branch after a PR was merged, by default? I am not sure under what usecases, you will end up with a lot of stale branches. And git fetch -pa should fix it locally |
| |
| ▲ | plqbfbv 9 minutes ago | parent | next [-] | | In Github it needs to be explicitly configured (Settings > General > Delete head branches after merging), Gitlab is the same. A lot of my developer colleagues don't know how git works, so they have no idea that "I merged the PR" != "I deleted the feature branch". I once had to cleanup a couple repositories that had hundreds of branches spanning back 5+ years. Nowadays I enforce it as the default project setting. | |
| ▲ | nightpool 9 minutes ago | parent | prev [-] | | `--prune` will delete your local copies of the origin's branches (e.g. `origin/whatever`). But it won't delete your local branches (e.g. `whatever` itself). So PRs that you've worked on or checked out locally will never get deleted. |
|
|
| ▲ | jakub_g 41 minutes ago | parent | prev | next [-] |
| The main issue with `git branch --merged` is that if the repo enforces squash merges, it obviously won't work, because SHA of squash-merged commit in main != SHA of the original branch HEAD. What tools are the best to do the equivalent but for squash-merged branches detections? Note: this problem is harder than it seems to do safely, because e.g. I can have a branch `foo` locally that was squash-merged on remote, but before it happened, I might have added a few more commits locally and forgot to push. So naively deleting `foo` locally may make me lose data. |
| |
| ▲ | masklinn 2 minutes ago | parent [-] | | Not just squash merges, rebase-merges also don't work. > What tools are the best to do the equivalent but for squash-merged branches detections? Hooking on remote branch deletion is what most people do, under the assumption that you tend to clean out the branches of your PRs after a while. But of course if you don't do that it doesn't work. |
|
|
| ▲ | micw 9 minutes ago | parent | prev | next [-] |
| I recently let copilot create a document with a few helpful git commands and that particular one was the one it came with as solution for exactly this case. |
|
| ▲ | gritzko an hour ago | parent | prev | next [-] |
| 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 32 minutes ago | parent [-] | | 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 14 minutes ago | parent [-] | | 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. |
|
|
|
| ▲ | trashymctrash 30 minutes ago | parent | prev | next [-] |
| If you squash your PR before merging, then this alternative worked really well for me: git fetch --prune && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
|
|
| ▲ | parliament32 an hour ago | parent | prev | next [-] |
| So effectively "I just discovered xargs"? Not to disparage OP but there isn't anything particularly novel here. |
| |
| ▲ | Someone1234 31 minutes ago | parent | next [-] | | This feels like gatekeeping someone sharing something cool they've recently learned. I personally lean more towards the "let's share cool little productivity tips and tricks with one another" instead of the "in order to share this you have to meet [entirely arbitrary line of novelty/cleverness/originality]." But each to their own I suppose. I wonder how you learned about using xargs? Maybe a blog-post or article not dissimilar to this one? | |
| ▲ | jimmydoe an hour ago | parent | prev | next [-] | | And they have to learn that from cia? That says so much about the generation we are in, just don’t go to school but learn math from mafia | |
| ▲ | skydhash 36 minutes ago | parent | prev [-] | | People really do need to read the “Unix Power Tools” book and realize their problem has been solved for decades. | | |
| ▲ | gosub100 20 minutes ago | parent [-] | | "People just need to find the info they don't know about, so then they'll know it." |
|
|
|
| ▲ | jo-m an hour ago | parent | prev | next [-] |
| I have something similar, but open fzf to select the branches to delete [1]. function fcleanb -d "fzf git select branches to delete where the upstream has disappeared"
set -l branches_to_delete (
git for-each-ref --sort=committerdate --format='%(refname:lstrip=2) %(upstream:track)' refs/heads/ | \
egrep '\[gone\]$' | grep -v "master" | \
awk '{print $1}' | $_FZF_BINARY --multi --exit-0 \
)
for branch in $branches_to_delete
git branch -D "$branch"
end
end
[1]: https://github.com/jo-m/dotfiles/blob/29d4cab4ba6a18dc44dcf9... |
|
| ▲ | taude 28 minutes ago | parent | prev | next [-] |
| I've had this in my ~/.bash_aliases for awhile: alias git-wipe-merged-branches='git branch --merged | grep -v \* | xargs git branch -D'
Trying to remember where I got that one, as I had commented the following version out: alias git-wipe-all-branches='git for-each-ref --format '%(refname:short)' refs/heads | grep -v master | xargs git branch -D'
|
|
| ▲ | d0liver 21 minutes ago | parent | prev | next [-] |
| 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. |
|
| ▲ | 1a527dd5 an hour ago | parent | prev | next [-] |
| 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. |
|
| ▲ | sigio an hour ago | parent | prev | next [-] |
| I've had this command as 'git drop-merged' for a few years now (put as a script in your path named git-drop-merged: #!/bin/sh
git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs --no-run-if-empty
git branch -d
|
|
| ▲ | stabbles 33 minutes ago | parent | prev | next [-] |
| Missed opportunity to call it `git ciao` |
|
| ▲ | dietr1ch 19 minutes ago | parent | prev | next [-] |
| Wait, why would the update for the silly master->main change be swapping the excluded regex instead of just excluding both? |
| |
|
| ▲ | Sesse__ 19 minutes ago | parent | prev | next [-] |
| You probably want git-dmb (dmb = delete merged branches) for a safe and more comprehensive way of dealing with this. |
| |
|
| ▲ | dewey an hour ago | parent | prev | next [-] |
| If you are using Fork.app on Mac as your git client, this now exists (For one month now) there too: https://github.com/fork-dev/Tracker/issues/2200#issuecomment... |
|
| ▲ | schiffern 38 minutes ago | parent | prev | next [-] |
| "ciaclean" is a nice touch. I assume CIA stands for Clean It All. |
| |
|
| ▲ | Arch-TK 40 minutes ago | parent | prev | next [-] |
| Unfortunately doesn't work if the project you work on squashes everything :( |
|
| ▲ | galbar an hour ago | parent | prev | next [-] |
| 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 |
| |
| ▲ | blakesterz an hour ago | parent [-] | | That's handy! I just started using oh-my-zsh and I feel like I know about 4% of useful things it can do so far. | | |
| ▲ | gjvc an hour ago | parent [-] | | "trapd00r" is the theme you want, if only because the name is cool | | |
| ▲ | giglamesh 26 minutes ago | parent [-] | | I change themes just often enough to completely forget how to do it and also forget whatever other adjustments I had to make to it all work. And like... is my config versioned somehow? This is a long way to say, Thank You for inspiring me to look at all that stuff again! |
|
|
|
|
| ▲ | bmacho 29 minutes ago | parent | prev [-] |
| > But deleting them one by one is tedious. The CIA’s dev team has a cleaner solution: git branch --merged | grep -v "\*\|master" | xargs -n 1 git branch -d
Why don't we all use a shell with lists and objects? That one line above could look like this git.branches()
.filter(b => b.merged && !b.current && b.name !== "master" && b.name !== "main")
.forEach(b => git.deleteBranch(b.name))
|