71 comments

  • fphilipe6 hours ago
    Here&#x27;s my take on the one-liner that I use via a `git tidy` alias[1]. A few points:<p>* It ensures the default branch is not deleted (main, master)<p>* It does not touch the current branch<p>* It does not touch the branch in a different worktree[2]<p>* It also works with non-merge repos by deleting the local branches that are gone on the remote<p><pre><code> git branch --merged &quot;$(git config init.defaultBranch)&quot; \ | grep -Fv &quot;$(git config init.defaultBranch)&quot; \ | grep -vF &#x27;*&#x27; \ | grep -vF &#x27;+&#x27; \ | xargs git branch -d \ &amp;&amp; git fetch \ &amp;&amp; git remote prune origin \ &amp;&amp; git branch -v \ | grep -F &#x27;[gone]&#x27; \ | grep -vF &#x27;*&#x27; \ | grep -vF &#x27;+&#x27; \ | awk &#x27;{print $1}&#x27; \ | xargs git branch -D </code></pre> [1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;fphilipe&#x2F;dotfiles&#x2F;blob&#x2F;ba9187d7c895e44c350f8e74d8bfbaaadbe97d6a&#x2F;gitconfig#L55" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fphilipe&#x2F;dotfiles&#x2F;blob&#x2F;ba9187d7c895e44c35...</a><p>[2]: <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;git-worktree" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;git-worktree</a>
    • rubinlinux4 hours ago
      The use of init.defaultBranch here is really problematic, because different repositories may use a different name for their default, and this is a global (your home directory scope) setting you have to pre-set.<p>I have an alias I use called git default which works like this:<p><pre><code> default = !git symbolic-ref refs&#x2F;remotes&#x2F;origin&#x2F;HEAD | sed &#x27;s@^refs&#x2F;remotes&#x2F;origin&#x2F;@@&#x27; </code></pre> then it becomes<p><pre><code> ...&quot;$(git default)&quot;... </code></pre> This figures out the actual default from the origin.
      • fphilipe3 hours ago
        I have a global setting for that. Whenever I work in a repo that deviates from that I override it locally. I have a few other aliases that rely on the default branch, such as “switch to the default branch”. So I usually notice it quite quickly when the value is off in a particular repo.
      • jeffrallen3 hours ago
        This is a great solution to a stupid problem.<p>I work at a company that was born and grew during the master-&gt;main transition. As a result, we have a 50&#x2F;50 split of main and master.<p>No matter what you think about the reason for the transition, any reasonable person must admit that this was a stupid, user hostile, and needlessly complexifying change.<p>I am a trainer at my company. I literally teach git. And: I have no words.<p>Every time I decide to NOT explain to a new engineer why it&#x27;s that way and say, &quot;just learn that some are master, newer ones are main, there&#x27;s no way to be sure&quot; a little piece of me dies inside.
    • tonymet3 hours ago
      This is a good one you should contribute it to git extras.
  • WickyNilliams7 hours ago
    I have a cleanup command that integrates with fzf. It pre selects every merged branch, so I can just hit return to delete them all. But it gives me the opportunity to deselect to preserve any branches if I want. It also prunes any remote branches<p><pre><code> # remove merged branches (local and remote) cleanup = &quot;!git branch -vv | grep &#x27;: gone]&#x27; | awk &#x27;{print $1}&#x27; | fzf --multi --sync --bind start:select-all | xargs git branch -D; git remote prune origin;&quot; </code></pre> <a href="https:&#x2F;&#x2F;github.com&#x2F;WickyNilliams&#x2F;dotfiles&#x2F;blob&#x2F;c4154dd9b698044bc8d28b93f813d6a38138c8d7&#x2F;.gitconfig#L41" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WickyNilliams&#x2F;dotfiles&#x2F;blob&#x2F;c4154dd9b6980...</a><p>I&#x27;ve got a few aliases that integrate with fzf like an interactive cherry pick (choose branch, choose 1 or more commits), or a branch selector with a preview panel showing commits to the side. Super useful<p>The article also mentions that master has changed to main mostly, but some places use develop and other names as their primary branch. For that reason I always use a git config variable to reference such branches. In my global git config it&#x27;s main. Then I override where necessary in any repo&#x27;s local config eg here&#x27;s an update command that updates primary and rebases the current branch on top:<p><pre><code> # switch to primary branch, pull, switch back, rebase update = !&quot;git switch ${1:-$(git config user.primaryBranch)}; git pull; git switch -; git rebase -;&quot; </code></pre> <a href="https:&#x2F;&#x2F;github.com&#x2F;WickyNilliams&#x2F;dotfiles&#x2F;blob&#x2F;c4154dd9b698044bc8d28b93f813d6a38138c8d7&#x2F;.gitconfig#L43" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WickyNilliams&#x2F;dotfiles&#x2F;blob&#x2F;c4154dd9b6980...</a>
    • lloeki7 hours ago
      &gt; For that reason I always use a git config variable to reference such branches. In my global git config it&#x27;s main<p><pre><code> $(git config user.primaryBranch) </code></pre> What about using git&#x27;s own `init.defaultBranch`?<p>I mean, while useless in terms of `git init` because the repo&#x27;s already init&#x27;d, this works:<p><pre><code> git config --local init.defaultBranch main </code></pre> And if you have `init.defaultBranch` set up already globally for `git init` then it all just works
      • WickyNilliams6 hours ago
        Hmm that might be nice actually. I like not conflating those two things, but as you say if the repo is already init&#x27;d then there&#x27;s no chance it&#x27;ll be used for the wrong purpose.<p>In any case the main thrust was just to avoid embeddings assumptions about branch names in your scripts :)
    • MathiasPius7 hours ago
      You can pull another branch without switching first:<p><pre><code> git switch my-test-branch ... git pull origin main:main git rebase main</code></pre>
      • hiccuphippo6 hours ago
        You can also rebase directly on the remote branch<p><pre><code> git fetch git rebase origin&#x2F;main</code></pre>
      • WickyNilliams6 hours ago
        Nice. That&#x27;ll make things a bit smoother. Changing branches often trips me up when I would later `git switch -`.
      • mroche6 hours ago
        Likewise with the other way around, just switch pull with push.
      • huntervang6 hours ago
        I have always done `git pull origin main -r`
  • lloeki8 hours ago
    I&#x27;ve had essentially that - if a bit fancier to accept an optional argument as well as handle common &quot;mainline&quot; branch names - aliased as `git lint` for a while:<p><pre><code> [alias] lint = !git branch --merged ${1-} | grep -v -E -e &#x27;^[*]?[ ]*(main|master|[0-9]+[.]([0-9]+|x)-stable)$&#x27; -e &#x27;^[*][ ]+&#x27; | xargs -r -n 1 git branch --delete </code></pre> so:<p><pre><code> git pull --prune &amp;&amp; git lint </code></pre> sits very high in my history stats
  • tholford14 minutes ago
    Consolidated approach based on the blog post + the comment thread here + my own dotfiles + Claude&#x27;s input:<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;tomholford&#x2F;0aa4cdb1340a9b5411ed6eaadabfcf37" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;tomholford&#x2F;0aa4cdb1340a9b5411ed6eaad...</a>
  • jakub_g8 hours ago
    The main issue with `git branch --merged` is that if the repo enforces squash merges, it obviously won&#x27;t work, because SHA of squash-merged commit in main != SHA of the original branch HEAD.<p>What tools are the best to do the equivalent but for squash-merged branches detections?<p>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.
    • otsaloma4 hours ago
      I recently revised my script to rely on (1) no commits in the last 30 days and (2) branch not found on origin. This is obviously not perfect, but it&#x27;s good enough for me and just in case, my script prompts to confirm before deleting each branch, although most of the time I just blindly hit yes.<p>To avoid losing any work, I have a habit of never keeping branches local-only for long. Additionally this relies on <a href="https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;repositories&#x2F;configuring-branches-and-merges-in-your-repository&#x2F;configuring-pull-request-merges&#x2F;managing-the-automatic-deletion-of-branches" rel="nofollow">https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;repositories&#x2F;configuring-branches...</a>
    • masklinn7 hours ago
      Not just squash merges, rebase-merges also don&#x27;t work.<p>&gt; What tools are the best to do the equivalent but for squash-merged branches detections?<p>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&#x27;t do that it doesn&#x27;t work.
    • laksdjf6 hours ago
      I have the same issue. Changes get pushed to gerrit and rebased on the server. This is what I have, though not perfected yet.<p><pre><code> prunable = &quot;!f() { \ : git log ; \ target=\&quot;$1\&quot;; \ [ -z \&quot;$target\&quot; ] &amp;&amp; target=$(git for-each-ref --format=\&quot;%(refname:short)\&quot; --count=1 refs&#x2F;remotes&#x2F;m&#x2F;); \ if [ -z \&quot;$target\&quot; ]; then echo \&quot;No remote branches found in refs&#x2F;remotes&#x2F;m&#x2F;\&quot;; return 1; fi; \ echo \&quot;# git branch --merged shows merged if same commit ID only\&quot; ;\ echo \&quot;# if rebased, git cherry can show branch HEAD is merged\&quot; ;\ echo \&quot;# git log grep will check latest commit subject only. if amended, this status won&#x27;t be accurate\&quot; ;\ echo \&quot;# Comparing against $target...\&quot;; \ echo \&quot;# git branch --merged:\&quot;; \ git branch --merged $target ;\ echo \&quot; ,- git cherry\&quot; ; \ echo \&quot; | ,- git log grep latest message\&quot;; \ for branch in $(git for-each-ref --format=&#x27;%(refname:short)&#x27; refs&#x2F;heads&#x2F;); do \ if git cherry \&quot;$target\&quot; \&quot;$branch\&quot; | tail -n 1 | grep -q \&quot;^-\&quot;; then \ cr=&quot;&quot;; \ else \ cr=&quot;&quot;; \ fi ; \ c=$(git rev-parse --short $branch) ; \ subject=$(git log -1 --format=%s \&quot;$branch\&quot; | sed &#x27;s&#x2F;[][(){}.^$\*+?|\\&#x2F;]&#x2F;\\\\&amp;&#x2F;g&#x27;) ; \ if git log --grep=\&quot;^$subject$\&quot; --oneline \&quot;$target\&quot; | grep -q .; then \ printf \&quot;$cr $c %-20s $subject\\n\&quot; $branch; \ else \ printf \&quot;$cr \\033[0;33m$c \\033[0;32m%-20s\\033[0m $subject\\n\&quot; $branch; \ fi; \ done; \ }; f&quot; </code></pre> (some emojis missing in above. see gist) <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;lawm&#x2F;8087252b4372759b2fe3b4052bf7e450" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;lawm&#x2F;8087252b4372759b2fe3b4052bf7e45...</a><p>It prints the results of 3 methods:<p>1. git branch --merged<p>2. git cherry<p>3. grep upstream git log for a commit with the same commit subject<p>Has some caveats, like if upstream&#x27;s commit was amended or the actual code change is different, it can have a false positive, or if there are multiple commits on your local branch, only the top commit is checked
      • arccy5 hours ago
        if you&#x27;re using gerrit then you have the Change-Id trailer you can match against?
    • samhclark7 hours ago
      Depends on your workflow, I guess. I don&#x27;t need to handle that case you noted and we delete the branch on remote after it&#x27;s merged. So, it&#x27;s good enough for me to delete my local branch if the upstream branch is gone. This is the alias I use for that, which I picked up from HN.<p><pre><code> # ~&#x2F;.gitconfig [alias] gone = ! &quot;git fetch -p &amp;&amp; git for-each-ref --format &#x27;%(refname:short) %(upstream:track)&#x27; | awk &#x27;$2 == \&quot;[gone]\&quot; {print $1}&#x27; | xargs -r git branch -D&quot; </code></pre> Then you just `git gone` every once in a while, when you&#x27;re between features.
    • WorldMaker7 hours ago
      This is my PowerShell variant for squash merge repos:<p><pre><code> function Rename-GitBranches { git branch --list &quot;my-branch-prefix&#x2F;*&quot; | Out-GridView -Title &quot;Branches to Zoo?&quot; -OutputMode Multiple | % { git branch -m $_.Trim() &quot;zoo&#x2F;$($_.Trim())&quot; } } </code></pre> `Out-GridView` gives a very simple dialog box to (multi) select branch names I want to mark finished.<p>I&#x27;m a branch hoarder in a squash merge repo and just prepend a `zoo&#x2F;` prefix. `zoo&#x2F;` generally sorts to the bottom of branch lists and I can collapse it as a folder in many UIs. I have found this useful in several ways:<p>1) It makes `git rebase --interactive` much easier when working with stacked branches by taking advantage of `--update-refs`. Merges do all that work for you by finding their common base&#x2F;ancestor. Squash merging you have to remember which commits already merged to drop from your branch. With `--update-refs` if I find it trying to update a `zoo&#x2F;` branch I know I can drop&#x2F;delete every commit up to that update-ref line and also delete the update-ref.<p>2) I sometimes do want to find code in intermediate commits that never made it into the squashed version. Maybe I tried an experiment in a commit in a branch, then deleted that experiment in switching directions in a later commit. Squashing removes all evidence of that deleted experiment, but I can still find it if I remember the `zoo&#x2F;` branch name.<p>All this extra work for things that merge commits gives you for free&#x2F;simpler just makes me dislike squash merging repos more.
    • de46le5 hours ago
      Mine&#x27;s this-ish (nushell, but easily bashified or pwshd) for finding all merged, including squashed:<p><pre><code> let t = &quot;origin&#x2F;dev&quot;; git for-each-ref refs&#x2F;heads&#x2F; --format=&quot;%(refname:short)&quot; | lines | where {|b| $b !~ &#x27;dev&#x27; and (git merge-tree --write-tree $t $b | lines | first) == (git rev-parse $&quot;($t)^{tree}&quot;) } </code></pre> Does a 3-way in-mem merge against (in my case) dev. If there&#x27;s code in the branch that isn&#x27;t in the target it won&#x27;t show up.<p>Pipe right to deletion if brave, or to a choice-thingy if prudent :)
  • gritzko7 hours ago
    If something this natural requires several lines of bash, something is just not right. Maybe branches should go sorted by default, either chronologically or topologically? git&#x27;s LoC budget is 20x LevelDBs or 30% of PostgreSQL or 3 SQLites. It must be able to do these things out of the box, isn&#x27;t it?<p><a href="https:&#x2F;&#x2F;replicated.wiki&#x2F;blog&#x2F;partII.html" rel="nofollow">https:&#x2F;&#x2F;replicated.wiki&#x2F;blog&#x2F;partII.html</a>
    • cloudfudge3 hours ago
      &quot;too many lines of bash&quot; and &quot;lines of code&quot; seem like very strange metrics to use to form these types of opinions.
  • nektro24 minutes ago
    wrote about something similar last year <a href="https:&#x2F;&#x2F;mlog.nektro.net&#x2F;posts&#x2F;2025&#x2F;git-deleteallotherbranches&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mlog.nektro.net&#x2F;posts&#x2F;2025&#x2F;git-deleteallotherbranche...</a>
  • whazor9 hours ago
    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&#x2F;rebase&#x2F;delete. As TUI library I use Textual which claude handles quite well, especially as it can test-run quite some Python code.
    • eulers_secret8 hours ago
      Tig is a nice and long-maintained git tui you might enjoy, then!<p>If nothing else maybe for inspiration
    • rw_panic0_08 hours ago
      how do you trust the code claude wrote? don&#x27;t you get anxiety &quot;what if there&#x27;s an error in tui code and it would mess up my git repo&quot;?
      • freedomben7 hours ago
        I&#x27;m not GP, but I have backups, plus I always make sure I&#x27;ve committed and pushed all code I care about to the remote. I do this even when running a prompt in an agent. That goes for running most things actually, not just CC. If claude code runs a git push -f then that could really hurt, but I have enough confidence from working with the agents that they aren&#x27;t going to do that that it&#x27;s worth it to me to take the risk in exchange for the convenience of using the agent.
      • embedding-shape7 hours ago
        &gt; how do you trust the code claude wrote?<p>If that&#x27;s something you&#x27;re worried about, review the code before running it.<p>&gt; don&#x27;t you get anxiety &quot;what if there&#x27;s an error in tui code and it would mess up my git repo&quot;?<p>I think you might want to not run untrusted programs in an environment like that, alternatively find a way of start being able to trust the program. Either approaches work, and works best depending on what you&#x27;re trying to do.
        • kaoD6 hours ago
          &gt; If that&#x27;s something you&#x27;re worried about, review the code before running it.<p>It takes <i>more</i>, not less, time to thoroughly review code you didn&#x27;t write.
          • embedding-shape6 hours ago
            Depends. If I was the one coming up with the implementation anyways, it&#x27;s basically just the &quot;coding&quot; part that was replaced with &quot;fingers hitting keyboard&quot; and &quot;agents writing to disk&quot;, so reviewing the code certainly is faster, you just have to &quot;check&quot; it, not understand it from scratch.<p>If we&#x27;re talking receiving random patches where first you have to understand the context, background and so on, then yeah I agree, it&#x27;ll take longer time probably than what it took for someone to hammer with their fingers. But again, I&#x27;m not sure that&#x27;s how professionals use LLMs right now, vibe-coding is a small hyped world mostly non-programmers seem to engage in.
            • kaoD6 hours ago
              &gt; you just have to &quot;check&quot; it, not understand it from scratch.<p>How can you &quot;check&quot; that which you don&#x27;t &quot;understand&quot;?<p>&gt; I&#x27;m not sure that&#x27;s how professionals use LLMs right now<p>I&#x27;m a professional and I can tell you how I use LLMs: I write code with their assistance, they don&#x27;t write code for me.<p>The few times I let Claude or Copilot loose, the results were heartbreaking and I spent more time reviewing (and then discarding) the code than what it took me to later write it from scratch.
              • embedding-shape4 hours ago
                &gt; How can you &quot;check&quot; that which you don&#x27;t &quot;understand&quot;?<p>??? I do understand, since I literally just instructed it, how would I otherwise? I&#x27;m not letting the LLM do the design, it&#x27;s all me still. So the &quot;understand&quot; already exists before the LLM even finished working.<p>&gt; I&#x27;m a professional and I can tell you how I use LLMs: I write code with their assistance, they don&#x27;t write code for me.<p>Hey, welcome to the club, me too :) I don&#x27;t write code, I write English prose, yet nothing is vibe coded, and probably I&#x27;ll end up being able to spend more time than you thinking about the design and architecture and how it fits in, because actual typing is no longer slowing me down. Yet again, every line is reviewed multiple times.<p>It&#x27;s more about the person behind the tools, than the tools themselves I think ultimately. Except for Copilot probably, the times I&#x27;ve tried it I&#x27;ve just not been able to produce code that is even slightly up to my standards. It&#x27;s a breeze with Codex though (5.2), and kind of hit and miss with Claude Code.
      • whazor6 hours ago
        I push my branches daily, so I wouldn&#x27;t lose that much work. If it breaks then I ask it to fix it.<p>But I do quickly check the output what it does, and especially the commands it runs. Sometimes it throws all code in a single file, so I ask for &#x27;good architecture with abstractions&#x27;.
        • zenoprax5 hours ago
          I see this regularly: &quot;I use GitHub to backup my local repos.&quot;<p>If `gh repo ...` commands get run you can lose everything instantly. You can force push and be left with a single blank commit on both sides. The agent has full control of everything, not just your local data.<p>Just set up Rclone&#x2F;restic and get your stuff into a system with some immutability.
          • tux19683 hours ago
            Force pushing doesn&#x27;t actually remove anything from the remote repository, only changes some references for which commits the branches point to. Plus, any forks on github will be completely unaffected. It&#x27;s not perfect, since Github doesn&#x27;t seem to offer any history of such reference alterations (a la the reflog), but it&#x27;s still a valuable offsite backup from a developer&#x27;s perspective.
            • zenoprax3 minutes ago
              Okay, fair enough re force pushing (though `gh repo delete` is still an option). I suppose for a sufficiently active codebase copies of it will exist elsewhere. Just seems odd to me that people aren&#x27;t backing up anything else on their computers otherwise they could trivially just include their git-based projects.
      • sclangdon8 hours ago
        Isn&#x27;t it this case no matter who wrote the code? How do you ever run anything if you&#x27;re worried about bugs?
        • phailhaus8 hours ago
          When I write the code myself, I&#x27;m not worried that I snuck a `git reset --hard` somewhere.
        • hennell6 hours ago
          Different type of creator, different type of bugs. I&#x27;d assume a human giving me a way to delete merged branches has probably had the same issue, solved the same problem and understands unspecified context around the problem (e.g protect local data). They probably run it themselves so bugs are most likely to occur in edge cases around none standard use as it works for them.<p>Ais are giving you what they get from common patterns, parsing documentation etc. Depending what you&#x27;re asking this might be an entirely novel combination of commands never run before. And depending on the model&#x2F;prompt it might solve in a way any human would balk at (push main to origin, delete .git, re-clone from origin. Merged local branches are gone!)<p>It&#x27;s like the ai art issues - people struggle with relative proportions and tones and making it look real. Ai has no issues with tones, but will add extra fingers or arms etc that humans rarely struggle with. You have to look for different things, and Ai bugs are definitely more dangerous than (most<i>) human bugs.<p>(</i>Depends a little, it&#x27;s pretty easy to tell if a human knows what they&#x27;re talking about. There&#x27;s for sure humans who could write super destructive code, but other elements usually make you suspicious and worried about the code before that)
        • layer85 hours ago
          It makes a difference whether an AI or a human wrote it. AIs make more random, inconsistent errors or omissions that a human wouldn’t make. AIs also don’t dog-feed their code the way human developers of tools usually do, catching more errors or unfit&#x2F;missing logic that way.
      • ithkuil7 hours ago
        I assume that whatever I type can be also flawed and take precautions like backups etc
      • fragmede2 hours ago
        It&#x27;s a git repo. What&#x27;s sort of mess-ups are you worried about that you can&#x27;t reflog your way out of (or ask claude code to fix)? It&#x27;s certainly possible to lose uncommitted work, but once it&#x27;s been committed, unless claude code goes and deletes .git entirely (which I&#x27;ve had codex do, so you&#x27;d better push it somewhere), you can&#x27;t lose work.
    • firesteelrain8 hours ago
      Can you explain TUI? I have never heard this before
      • Bjartr8 hours ago
        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.<p>Really, they&#x27;re just a GUI drawn with Unicode instead of drawing primitives.<p>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&#x27;t.
        • Muvasa8 hours ago
          I prefer tui&#x27;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.<p>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.<p>It&#x27;s not about saving time. It&#x27;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)
          • kstrauser6 hours ago
            That’s an excellent way to explain it. I’m already in the shell doing stuff. Whenever I can stay there without sacrificing usability, it’s a big boost.
          • irl_zebra7 hours ago
            &quot;It&#x27;s not about saving time, it&#x27;s about eliminating the mental toll from having to context switch&quot;<p>This broke my brain! Woah!
        • criddell8 hours ago
          &gt; an interactive page that can be navigated around with the keyboard<p>Or mouse &#x2F; trackpad.<p>I really haven&#x27;t seen anything better for making TUIs than Borland&#x27;s Turbo Vision framework from 35ish years ago.
      • GCUMstlyHarmls8 hours ago
        Eg: lazygit <a href="https:&#x2F;&#x2F;github.com&#x2F;jesseduffield&#x2F;lazygit?tab=readme-ov-file#features" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jesseduffield&#x2F;lazygit?tab=readme-ov-file#...</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;sxyazi&#x2F;yazi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sxyazi&#x2F;yazi</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;darrenburns&#x2F;posting" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;darrenburns&#x2F;posting</a> or I guess <i>Vim</i> would be a prominent example.<p>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 &quot;graphical widgets&quot; like buttons, bars, hotkeys, panes, etc.
        • giglamesh8 hours ago
          So the acronym is for Terrible User Interface? ;)
          • worksonmine7 hours ago
            TUI is peak UI, anyone who disagrees just don&#x27;t get it. Every program listens to the same keybindings, looks the same and are composable to work together. You don&#x27;t get that clicking buttons with the mouse. It&#x27;s built to get the work done not look pretty.
          • allarm8 hours ago
            No it&#x27;s not.
      • layer85 hours ago
        <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Text-based_user_interface" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Text-based_user_interface</a>
      • ses19848 hours ago
        Terminal UI.
      • booleandilemma8 hours ago
        It&#x27;s definitely an acronym that got popular in the last year or so, though I&#x27;m sure there are people out there who will pretend otherwise. I&#x27;ve been in the industry 15+ years now and never heard it before. Previously it was just UI, GUI, or CLI.
        • freedomben7 hours ago
          It&#x27;s gotten more popular for sure, but it&#x27;s definitely been around a long time. Even just on HN there have been conversation about gdb tui ever since I&#x27;ve been here (starting browsing HN around 2011). For anyone who works in embedded systems it&#x27;s a very common term and has been since I got into it in 2008-ish. I would guess it was much more of a linux&#x2F;unix user thing until recently though, so people on windows and mac probably rarely if ever intersected with the term, so that&#x27;s definitely a change. Just my observations.
        • 0x1ch6 hours ago
          My friends and I have been actively in the &quot;CLI&#x2F;TUI&quot; since middle school. Anyone tinkering on linux that used tiling window managers is already very familiar with the domain.
        • snozolli6 hours ago
          As someone who came up using Borland&#x27;s Turbo Pascal, Turbo C, and Turbo Vision (their OOP UI framework), it was called CUI (character-based user interface) to distinguish from GUI, which became relevant as Windows became dominant.<p>I never heard &quot;TUI&quot; until the last few years, but it may be due to my background being Microsoft-oriented.<p>One of the only references I can find is the PC Magazine encyclopedia: <a href="https:&#x2F;&#x2F;www.pcmag.com&#x2F;encyclopedia&#x2F;term&#x2F;cui" rel="nofollow">https:&#x2F;&#x2F;www.pcmag.com&#x2F;encyclopedia&#x2F;term&#x2F;cui</a>
      • KPGv28 hours ago
        [flagged]
        • TarqDirtyToMe8 hours ago
          They aren’t the same thing. TUI refers to interactive ncurses-like interfaces. Vim has a TUI, ls does not<p>I’m fairly certain this terminology has been around since at least the early aughts.
        • cristoperb8 hours ago
          I don&#x27;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.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;w&#x2F;index.php?title=Text-based_user_interface&amp;oldid=6633714" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;w&#x2F;index.php?title=Text-based_user_i...</a>
        • philiplu8 hours ago
          Sorry, but this 65 yo grey-beard disagrees. A TUI to me, back in the 80s&#x2F;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.
          • bombcar7 hours ago
            Exactly. A CLI is a single line - like edlin. A TUI takes over all or most of the screen, like edit or vi or emacs.<p>Norton Commander (or Midnight Commander) is probably the quintessential example of a powerful TUI; it can do things that would be quite hard to replicate as easily in a CLI.
          • KPGv27 hours ago
            We might&#x27;ve been caught on different parts of the wave. I checked Ngrams out of curiosity<p><a href="https:&#x2F;&#x2F;books.google.com&#x2F;ngrams&#x2F;graph?content=TUI&amp;year_start=1800&amp;year_end=2022&amp;corpus=en&amp;smoothing=3" rel="nofollow">https:&#x2F;&#x2F;books.google.com&#x2F;ngrams&#x2F;graph?content=TUI&amp;year_start...</a><p>Basically it was never used, then it was heavily used, and then never used, and then in the early 00s it took off again.<p>That&#x27;d explain why you used it, I never did, and now young kids are.
            • marssaxman7 hours ago
              Thanks for looking that up! It makes sense, of course - the line starts to drop in 1984, with the release of the Macintosh, and hits a trough around the launch of Windows 95.<p>It&#x27;s not a term I recall hearing at all when I started using computers in the mid-&#x27;80s - all that mattered back then was &quot;shiny new GUI, or the clunky old thing?&quot; I really thought it was a retroneologism when I first heard it, maybe twenty years ago.
            • rjmunro5 hours ago
              I don&#x27;t think that search is very valid - the TUI group travel companies are likely much more mentioned than Terminal User Interface. They are pretty big around the world and have an airline, cruises, hotels etc.
        • john_strinlai7 hours ago
          [dead]
    • kqr7 hours ago
      In the case of Git, I can warmly recommend Magit as a TUI. Not only does it make frequent operations easier and rare operations doable -- it also teaches you Git!<p>I have a draft here about one aspect of Magit I enjoy: <a href="https:&#x2F;&#x2F;entropicthoughts.com&#x2F;rebasing-in-magit" rel="nofollow">https:&#x2F;&#x2F;entropicthoughts.com&#x2F;rebasing-in-magit</a>
    • Trufa8 hours ago
      The amount of little tools I&#x27;m creating for myself is incredible, 4.6 seems like it can properly one&#x2F;two shot it now without my attention.<p>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&#x27;t wanna npm i that takes forever.<p>Also, if you share it with me, there&#x27;s obviously no expectations, even it&#x27;s a half backed vibecoded mess.
      • whazor6 hours ago
        This is how I solve the dependencies with Nix: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;whazor&#x2F;bca8b687e26081e77d818bc26033c029" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;whazor&#x2F;bca8b687e26081e77d818bc26033c...</a><p>Nix helps Claude a lot with dependencies, it can add stuff and execute the flake as well.<p>I will come back to you with project itself.
      • unshavedyak7 hours ago
        I’ve been wanting similar but have instead been focused on GUI. My #1 issue with TUI is that I’ve never liked code jumps very smooth high fps fast scrolling. Between that and terminal lacking variable font sizes, I’d vastly prefer TUIs, but I just struggle to get over those two issues.<p>I’ve been entirely terminal based for 20 years now and those issues have just worn me down. Yet I still love terminal for its simplicity. Rock and a hard place I guess.
      • SauntSolaire7 hours ago
        What&#x27;s the point of open sourcing something you one shot with an LLM? At that point just open source the prompt you used to generate it.
        • freedomben7 hours ago
          Testing. If you share something you&#x27;ve tested and know works, that&#x27;s way better than sharing a prompt which will generate untested code which then has to be tested. On top of that it seems wasteful to burn inference compute (and $) repeating the same thing when the previous output would be superior anyway.<p>That said, I do think it would be awesome if including prompts&#x2F;history in the repos somehow became a thing. Not only would it help people learn and improve, but it would allow tweaking.
        • NetOpWibby7 hours ago
          To save time and energy?
      • elliotbnvl8 hours ago
        The deps question is huge, let me know if you solve it.
        • CalebJohn7 hours ago
          If I&#x27;m understanding the problem correctly, this should be solved by pnpm [1]. It stores packages in a global cache, and hardlinks to the local node_packages. So running install in a new worktree should be instant.<p>[1]: <a href="https:&#x2F;&#x2F;pnpm.io&#x2F;motivation" rel="nofollow">https:&#x2F;&#x2F;pnpm.io&#x2F;motivation</a>
    • hattmall8 hours ago
      What are some examples of useful TUI you made? I&#x27;m generally opposed to the concept
    • lionkor8 hours ago
      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
      • htnthrow112208 hours ago
        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.
      • MarsIronPI8 hours ago
        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.
      • bmacho8 hours ago
        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.<p>Maybe I&#x27;ll try using small TUI too.
      • duneisagoodbook8 hours ago
        yeah! they should focus on more productive pursuits, like telling people online what to do with their time and resources.
        • morissette8 hours ago
          And these are things outside of our control.
  • parliament329 hours ago
    So effectively &quot;I just discovered xargs&quot;? Not to disparage OP but there isn&#x27;t anything particularly novel here.
    • Someone12348 hours ago
      This feels like gatekeeping someone sharing something cool they&#x27;ve recently learned.<p>I personally lean more towards the &quot;let&#x27;s share cool little productivity tips and tricks with one another&quot; instead of the &quot;in order to share this you have to meet [entirely arbitrary line of novelty&#x2F;cleverness&#x2F;originality].&quot;<p>But each to their own I suppose. I wonder how <i>you</i> learned about using xargs? Maybe a blog-post or article not dissimilar to this one?
      • parliament327 hours ago
        I don&#x27;t think there&#x27;s anything wrong with sharing something cool, even if it&#x27;s trivial to other people. The problem is framing a blog post with &quot;ooh this was buried in the secret leaked CIA material&quot;.. and then the reader opens it to find out it&#x27;s just xargs. It feels very clickbaity. Akin to &quot;here&#x27;s one simple trick to gain a treasure trove of information about all the secret processes running on your system!!&quot; and it&#x27;s just ps.
        • audience_mem3 hours ago
          It felt almost like satire to me, especially with the name &quot;ciaclean&quot;.
      • superxpro127 hours ago
        No I agree with you. This whole aura of &quot;well IIIII knew this and YOUUUUU didnt&quot; needs to die. I get that it&#x27;s sometimes redundant and frustrating to encounter the same question a few times... but there&#x27;s always new people learning in this world, and they deserve a chance to learn too.<p>Why do people constantly have to be looking for any way to justify their sense of superiority over others? Collaborative attitudes are so much better for all involved.
    • jimmydoe8 hours ago
      And they have to learn that from cia?<p>That says so much about the generation we are in, just don’t go to school but learn math from mafia
      • vntok7 hours ago
        Where else would you learn about triple-entry bookkeeping?
    • oldestofsports2 hours ago
      It&#x27;s cool that it comes from CIA, and someone who doesn&#x27;t know about xargs may just learn something new. What is not to like?
    • ggrab5 hours ago
      Lots of negative sentiment on your comment, but I was going to write the same. Hopefully AI won’t make us forget that good command line tools are designed to be chained together if you want to achieve something that’s perhaps too niche as a use case to make it into a native command. It’s worth learning about swiss army utilities like xargs that make this easy (and fun)
    • mrexcess3 hours ago
      Seriously, this seems like someone in awe of xargs. Maybe its the Bell Labs in me but this is boilerplate stuff.
    • skydhash8 hours ago
      People really do need to read the “Unix Power Tools” book and realize their problem has been solved for decades.
      • gosub1008 hours ago
        &quot;People just need to find the info they don&#x27;t know about, so then they&#x27;ll know it.&quot;
        • gavinray6 hours ago
          I don&#x27;t find that the insinuation of the parent comment at all.<p>Saying &quot;If you read X book, you&#x27;ll realize it&#x27;s a solved problem&quot; IS the information -- the name of the book you need to read
        • SoftTalker6 hours ago
          People need to be curious. Then they seek out the info they don&#x27;t know about.
    • cgfjtynzdrfht8 hours ago
      [dead]
  • jo-m8 hours ago
    I have something similar, but open fzf to select the branches to delete [1].<p><pre><code> function fcleanb -d &quot;fzf git select branches to delete where the upstream has disappeared&quot; set -l branches_to_delete ( git for-each-ref --sort=committerdate --format=&#x27;%(refname:lstrip=2) %(upstream:track)&#x27; refs&#x2F;heads&#x2F; | \ egrep &#x27;\[gone\]$&#x27; | grep -v &quot;master&quot; | \ awk &#x27;{print $1}&#x27; | $_FZF_BINARY --multi --exit-0 \ ) for branch in $branches_to_delete git branch -D &quot;$branch&quot; end end </code></pre> [1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;jo-m&#x2F;dotfiles&#x2F;blob&#x2F;29d4cab4ba6a18dc44dcf9bf476c6f4e81c53e3f&#x2F;private_dot_config&#x2F;private_fish&#x2F;conf.d&#x2F;fzf.fish.tmpl#L85" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jo-m&#x2F;dotfiles&#x2F;blob&#x2F;29d4cab4ba6a18dc44dcf9...</a>
  • arusahni8 hours ago
    I use this alias:<p><pre><code> prune-local = &quot;!git fetch -p &amp;&amp; for branch in $(git branch -vv | awk &#x27;&#x2F;: gone]&#x2F;{if ($1!=\&quot;\*\&quot;) print $1}&#x27;); do git branch -d $branch; done&quot; </code></pre> 1. Fetch the latest from my remote, removing any remote tracking branches that no longer exist<p>2. Enumerate local branches, selecting each that has been marked as no longer having a remote version (ignoring the current branch)<p>3. Delete the local branch safely
  • kccqzy2 hours ago
    Why not just git dmb? <a href="https:&#x2F;&#x2F;manpages.debian.org&#x2F;testing&#x2F;git-delete-merged-branches&#x2F;git-dmb.1.en.html" rel="nofollow">https:&#x2F;&#x2F;manpages.debian.org&#x2F;testing&#x2F;git-delete-merged-branch...</a>
  • andrewaylett5 hours ago
    I keep a command `git-remove-merged`, which uses `git ls-remote` to see if the branch is set up to track a remote branch, and if it <i>is</i> then whether the remote branch still exists. On the assumption that branches which have had remote tracking but no longer do are either merged or defunct.<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;andrewaylett&#x2F;27c6a33bd2fc8c99eada60589f0ca31f" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;andrewaylett&#x2F;27c6a33bd2fc8c99eada605...</a><p>But actually nowadays I use JJ and don&#x27;t worry about named branches :).
  • EricRiese7 hours ago
    Much more complicated than necessary. I just use<p>git branch | xargs git branch -d<p>Don&#x27;t quote me, that&#x27;s off the top of my head.<p>It won&#x27;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&#x2F;develop.<p>Sometimes I intentionally delete develop if my develop branch is far behind the feature branch I&#x27;m on. If I don&#x27;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.
  • Cherub07748 hours ago
    We all have something similar, it seems! I stole mine from <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7726949&#x2F;remove-tracking-branches-no-longer-on-remote#comment91928557_38404202" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7726949&#x2F;remove-tracking-...</a>.<p>I also set mine up to run on `git checkout master` so that I don&#x27;t really have to think about it too hard -- it just runs automagically. `gcm` has now become muscle memory for me.<p><pre><code> alias gcm=$&#x27;git checkout master || git checkout main &amp;&amp; git pull &amp;&amp; git remote prune origin &amp;&amp; git branch -vv | grep \&#x27;: gone]\&#x27;| grep -v &quot;\*&quot; | awk \&#x27;{ print $1; }\&#x27; | xargs -r git branch -D&#x27;</code></pre>
    • masklinn8 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:<p><pre><code> &#x27;!f() { git branch --format &#x27;%(refname:short) %(upstream:track,nobracket)&#x27; | awk &#x27;$2~&#x2F;^gone$&#x2F;{print $1}&#x27; | xargs git branch -D; }; f&#x27;</code></pre>
  • rudnevr2 hours ago
    What&#x27;s wrong with just deleting the whole folder and clone repo and whatever branch you&#x27;re interested in? In any case it&#x27;s not an urgent thing. You don&#x27;t have to do this mid-work, you can wait until you push most stuff and then rm &amp;&amp; git clone.<p>The only case in which this wouldn&#x27;t work is when you have a ton of necessary local branches you can&#x27;t even push to remote, which is a risk and anti-pattern per se.
    • efficax2 hours ago
      because of my precious stash? but also the repo is huge, the clone takes 10 minutes? And all the other branches...
      • 9dev2 hours ago
        &gt; because of my precious stash?<p>you mean the… <i>pile of shame</i>?
      • rudnevr2 hours ago
        doesn&#x27;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&#x27;s by definition a rare operation. A ton of branches doesn&#x27;t grow overnight.
  • sigio8 hours ago
    I&#x27;ve had this command as &#x27;git drop-merged&#x27; for a few years now (put as a script in your path named git-drop-merged:<p><pre><code> #!&#x2F;bin&#x2F;sh git branch --merged | egrep -v &quot;(^\*|master|main|dev)&quot; | xargs --no-run-if-empty git branch -d</code></pre>
  • d0liver8 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&#x2F;main, and usually when I need to look at them I checkout the remote branches instead.
  • andix2 hours ago
    I sometimes convert old branches to tags. So they don&#x27;t show up in the list of branches, but I never lose any branches by accident.<p>All those &quot;merged&quot; workflows only work, if you actually merge the branches. It doesn&#x27;t work with a squash merge workflow.<p>edit: I delegate this task to a coding agent. I&#x27;m really bad at bash commands. yolo!
  • renlo2 hours ago
    I use this tool, which allows one to select the branches to delete instead of just deleting everything: <a href="https:&#x2F;&#x2F;github.com&#x2F;stefanwille&#x2F;git-branch-delete" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stefanwille&#x2F;git-branch-delete</a><p>Unfortunately its name makes it hard to search for and find.
  • atomicUpdate1 hour ago
    This is the same thing as `git rebase-update`, available in Chrome&#x27;s `depot_tools`, which deletes merged branches.<p>Beyond that, this is just OP learning how `xargs` works.
  • maerF0x07 hours ago
    <p><pre><code> DEFAULT_BRANCH=$(git remote show origin | sed -n &#x27;&#x2F;HEAD branch&#x2F;s&#x2F;.*: &#x2F;&#x2F;p&#x27;) git branch --merged &quot;origin&#x2F;$DEFAULT_BRANCH&quot; \ | grep -vE &quot;^\s*(\*|$DEFAULT_BRANCH)&quot; \ | xargs -r -n 1 git branch -d </code></pre> This is the version I&#x27;d want in my $EMPLOYER&#x27;s codebase that has a mix of default branches
  • gritzko8 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)<p><a href="https:&#x2F;&#x2F;replicated.wiki&#x2F;blog&#x2F;partII.html#navigating-the-history" rel="nofollow">https:&#x2F;&#x2F;replicated.wiki&#x2F;blog&#x2F;partII.html#navigating-the-hist...</a>
    • oniony8 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.
      • gritzko8 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&#x2F;performance discrepancy. git is overweight for what it does, if they make it do only the bottom 20%, then things will get funny.<p>Still, many oddities of git are inevitable due to its underlying storage model, so it makes sense to explore other models too.
  • kazinator3 hours ago
    Or don&#x27;t go crazy making branches in the first place.<p>Have a merge workflow which deletes the branch right there.
  • coderpersson7 hours ago
    `git trash`<p><a href="https:&#x2F;&#x2F;github.com&#x2F;henrikpersson&#x2F;git-trash" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;henrikpersson&#x2F;git-trash</a><p>I use this script with a quick overview to prevent accidentally deleting something important
  • nikeee7 hours ago
    I use git-trim for that:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;foriequal0&#x2F;git-trim" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;foriequal0&#x2F;git-trim</a><p>Readme also explains why it&#x27;s better than a bash-oneliner in some cases.
  • 1a527dd58 hours ago
    I use<p><pre><code> #!&#x2F;bin&#x2F;sh git checkout main git fetch --prune git branch | grep -v main | xargs --no-run-if-empty git branch -D git pull </code></pre> Save that next to your git binary, call it whatever you want. It&#x27;s destructive on purpose.
  • jimnotgym7 hours ago
    I have an image of running his command, &#x27;ciaclean&#x27;, and a black van turnes up with a bunch of agents in coveralls, brandishing rolls of polyethylene sheeting and drums of acid.
  • WorldMaker7 hours ago
    I use this PowerShell variant:<p><pre><code> function Remove-GitBranches { git branch --merged | Out-GridView -Title &quot;Branches to Remove?&quot; -OutputMode Multiple | % { git branch -d $_.Trim() } } </code></pre> `Out-GridView` gives you a quick popup dialog with all the branch names that supports easy multi-select. That way you get a quick preview of what you are cleaning up and can skip work in progress branch names that you haven&#x27;t committed anything to yet.
  • tonmoy4 hours ago
    I’m surprised to see not enough people using xargs, or maybe I overuse it
  • cowlby7 hours ago
    Anyone else &quot;vibe git-ing” lately? I just ask Claude Opus to clean it up and it does really well. Same for build commands and test harnesses.
    • mywittyname7 hours ago
      It does a pretty good job, but I still don&#x27;t completely trust it with keys to the kingdom.<p>I have replaced my standard ddg of, &quot;git &lt;the thing i need&gt;&quot; with asking Claude to give me the commands I need to run.
  • taude8 hours ago
    I&#x27;ve had this in my ~&#x2F;.bash_aliases for awhile:<p><pre><code> alias git-wipe-merged-branches=&#x27;git branch --merged | grep -v \* | xargs git branch -D&#x27; </code></pre> Trying to remember where I got that one, as I had commented the following version out:<p><pre><code> alias git-wipe-all-branches=&#x27;git for-each-ref --format &#x27;%(refname:short)&#x27; refs&#x2F;heads | grep -v master | xargs git branch -D&#x27;</code></pre>
  • Sesse__8 hours ago
    You probably want git-dmb (dmb = delete merged branches) for a safe and more comprehensive way of dealing with this.
    • puzz8 hours ago
      Or git-old-branches&#x2F;git-recent from git-plus<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tkrajina&#x2F;git-plus" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tkrajina&#x2F;git-plus</a><p>Disclaimer, I&#x27;m the author ^^
  • dewey8 hours ago
    If you are using Fork.app on Mac as your git client, this now exists (For one month now) there too: <a href="https:&#x2F;&#x2F;github.com&#x2F;fork-dev&#x2F;Tracker&#x2F;issues&#x2F;2200#issuecomment-3823055759" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fork-dev&#x2F;Tracker&#x2F;issues&#x2F;2200#issuecomment...</a>
  • stabbles8 hours ago
    Missed opportunity to call it `git ciao`
  • jldugger6 hours ago
    This looks loosely like something already present in git-extras[1].<p><pre><code> [1]: https:&#x2F;&#x2F;github.com&#x2F;tj&#x2F;git-extras&#x2F;blob&#x2F;main&#x2F;Commands.md#git-delete-merged-branches</code></pre>
  • devy6 hours ago
    I needed that exact functionality and Claude code and ChatGPT consistently showing this same exact combo CLI receipt with the simple prompt &quot;how to do use CLI to remove merged branch locally.&quot;
    • SoftTalker6 hours ago
      It&#x27;s hardly a profound insight. If you&#x27;re fluent at the command line, xargs enables all sorts of conveniences.
  • microflash5 hours ago
    I’ve been using something similar for years with Nushell.<p>git branch | lines | where ($it !~ &#x27;^*&#x27;) | each {|br| git branch -D ($br | str trim)} | str trim
  • bobabob6 hours ago
    Using grep and xargs is worth a whole blog post now? hmmmmm
    • allthetime3 hours ago
      bash knowledge is probably a quickly dying thing.<p>hey, gemini, how do I...
  • password43218 hours ago
    I don&#x27;t delete branches, I just work with the top several most recently modified.
    • the_real_cher7 hours ago
      How to list those? Is there a flag for git branch to sort by recently modified?<p>(not on my computer right now to check)
      • rpozarickij7 hours ago
        This isn&#x27;t exactly the same but I&#x27;ve been using git-recent [0] (with `gr` alias) for many years. It sorts branches based on checkout order (which is what I usually need when switching between branches) and allows to easily choose a branch to checkout to.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent</a>
      • embedding-shape7 hours ago
        I do `gb` (probably &quot;git branch&quot; when I set that up) which apparently is an alias to `git for-each-ref --sort=-committerdate refs&#x2F;heads&#x2F; --format=&#x27;%(refname:short)&#x27; | tac`, displays a list with the latest changed branch at the bottom. Remove the `| tac` for the reverse order.
        • password43211 hour ago
          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:<p><pre><code> git fetch --all --prune --quiet git log origin&#x2F;main --date=format:%m%d%H%M --pretty=format:&#x27;%C(yellow)%ad-%h%C(auto)%d %s (%cn)&#x27; -n1 git log --tags --date=format:%m%d%H%M --pretty=format:&#x27;%C(yellow)%ad-%h%C(auto)%d %s (%cn)&#x27; -n1 echo &#x27;&#x27; git for-each-ref --count=10 --sort=-committerdate refs&#x2F;heads&#x2F; --format=&#x27;%(color:yellow)%(committerdate:format:%m%d%H%M)-%(objectname:short) (%(color:green)%(refname:short)%(color:yellow)) %(color:white)%(contents:subject) (%(authorname))&#x27; </code></pre> 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.
  • trashymctrash8 hours ago
    If you squash your PR before merging, then this alternative worked really well for me:<p><pre><code> git fetch --prune &amp;&amp; git branch -vv | awk &#x27;&#x2F;: gone]&#x2F;{print $1}&#x27; | xargs git branch -D</code></pre>
    • lkbm6 hours ago
      Almost identical to mine, but you&#x27;ve got smarter awk use: `git prune origin &amp;&amp; git branch -vv | grep &#x27;origin&#x2F;.*: gone]&#x27; | awk &#x27;{print $1}&#x27; | xargs git branch -D`<p>I think I probably copied this from Stack Overflow close to a decade ago. Seems like a lot of people have very similar variations.
  • ihsoy8 hours ago
    Dont most git instances, like github, delete branch after a PR was merged, by default?<p>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
    • nightpool8 hours ago
      `--prune` will delete your local copies of the <i>origin&#x27;s</i> branches (e.g. `origin&#x2F;whatever`). But it won&#x27;t delete your <i>local</i> branches (e.g. `whatever` itself). So PRs that you&#x27;ve worked on or checked out locally will never get deleted.
    • plqbfbv8 hours ago
      In Github it needs to be explicitly configured (Settings &gt; General &gt; Delete head branches after merging), Gitlab is the same.<p>A lot of my developer colleagues don&#x27;t know how git works, so they have no idea that &quot;I merged the PR&quot; != &quot;I deleted the feature branch&quot;. I once had to cleanup a couple repositories that had hundreds of branches spanning back 5+ years.<p>Nowadays I enforce it as the default project setting.
    • embedding-shape7 hours ago
      &gt; Dont most git instances, like github, delete branch after a PR was merged, by default?<p>By default, I don&#x27;t think so. And even if the branch is deleted, objects can still be there. I think GitLab has a &quot;Clean stale objects&quot; thing you can trigger, I don&#x27;t seem to recall ever seeing any &quot;Git Maintenance&quot; UI actions on GitHub so not sure how it works there.
  • mrbonner7 hours ago
    &gt; Since most projects now use main instead of master…<p>I see that even the CIA, a federal government office, has not fully used DEI approved, inclusive language yet :-)
    • jen207 hours ago
      The leaked material from which this came was described as being from 2017, which makes that the latest this could have been written - GitHub only changed the default for new repos in October of 2020, and there had only been consensus building around the switch for a couple of years beforehand.
  • samtrack20195 hours ago
    gh-poi plugin is a must if you manage a lot of github pr and want to easily clean the branch attached to it when pr is merged <a href="https:&#x2F;&#x2F;github.com&#x2F;seachicken&#x2F;gh-poi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;seachicken&#x2F;gh-poi</a>
  • micw8 hours ago
    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.
  • block_dagger7 hours ago
    I cleanup branches interactively with a few lines of bash, which takes a bit more time but is less likely to destroy active work.
  • dietr1ch8 hours ago
    Wait, why would the update for the silly master-&gt;main change be swapping the excluded regex instead of just excluding both?
    • PunchyHamster8 hours ago
      coz OP has agenda and<p>&gt; Since most projects now use main instead of master<p>some delusions to boot
  • markus_zhang7 hours ago
    Oh this is what ChatGPT told me when I asked &quot;How to remove all local branch except main&quot;...
  • spectaclepiece2 hours ago
    how is this a news item. LLMs figured this out for me two years ago
  • galbar9 hours ago
    The git plugin in oh-my-zsh has an alias for this: gbda<p>It also has one for squash-merged branches: gbds<p>Very useful I&#x27;ve been using them for years
    • blakesterz8 hours ago
      That&#x27;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.
      • gjvc8 hours ago
        &quot;trapd00r&quot; is the theme you want, if only because the name is cool
        • giglamesh8 hours ago
          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!
  • tpoacher3 hours ago
    grep + xargs ... in other words, we&#x27;re finally back at good old standard svn workflows
  • Arch-TK8 hours ago
    Unfortunately doesn&#x27;t work if the project you work on squashes everything :(
  • schiffern8 hours ago
    &quot;ciaclean&quot; is a nice touch.<p>I assume CIA stands for Clean It All.
    • sammyteee8 hours ago
      &quot;Clean It All, Clean&quot; :P
      • schiffern15 minutes ago
        At least someone got it, lol. &quot;GNU is Not Unix&quot; et al. ;)<p>Clean It All Clean also sounds like a 50s detergent slogan, so it&#x27;s got that going for it.
    • plufz8 hours ago
      I assume it means mess up commit history and install ”our” BDFL.
  • fragmede2 hours ago
    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 = &quot;!alias ciaclean=&#x27;git branch --merged origin&#x2F;main | grep -vE &quot;^\s<i>(*|main|develop)&quot; | xargs -n 1 git branch -d&#x27;&quot;<p>so then it&#x27;s `git ciaclean` and not bare `ciaclean` which imo is cleaner.</i>
  • arduanika4 hours ago
    Trust Langley to neatly tie up all the loose ends.
  • locallost3 hours ago
    I&#x27;ve used this for about 10 years now. Pretty sure it was a widespread way of doing it before any CIA leak.
  • rickknowlton7 hours ago
    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:<p><pre><code> git branch --merged origin&#x2F;main --format=&quot;%(refname:short)&quot; \ | grep -vE &quot;^(main|develop)$&quot; \ | xargs -r git branch -d </code></pre> that said... pretty hilarious a dev was just like &quot;uhh yeah ciaclean...&quot; curious what... other aliases they might have??
  • Svoka5 hours ago
    I work with GitHub, so this oneliner relly helps me out. It also doesn&#x27;t rely on grep, since --format have all you need:<p><pre><code> git branch --format &#x27;%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)&#x27; --omit-empty | xargs --verbose -r git branch -D </code></pre> It deletes all the branches for which remotes were deleted. GitHub deletes branches after PR was merged. I alias it to delete-merged
  • freecodyx2 hours ago
    i once used ai to generate a command doing the exact same thing.<p>git branch -vv | grep &#x27;: gone\]&#x27; | awk &#x27;{print $1}&#x27; | xargs -n 1 git branch -D
  • devhouse7 hours ago
    don&#x27;t forget to fetch first
  • nivcmo4 hours ago
    [dead]
  • bobjordan6 hours ago
    I use `master` in all my repos because I&#x27;ve been using it since forever and it never has once occurred to me &quot;oh shit I better change it to `main` this time in case `master` may offend somebody some day. Unfortunately, that&#x27;s the last thing on my mind when I&#x27;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&#x27;ll subtly break something and I just don&#x27;t have enough hours left in my life to accept yet unknown risk that it&#x27;ll cost me even more hours, just to make some random sensitive developer not get offended one day.
    • joshuamcginnis6 hours ago
      Also, git&#x27;s &quot;master&quot; 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.
      • ear7h5 hours ago
        Nope, the term comes from bitkeeper which does refer to master&#x2F;slave.<p>See this email for some references:<p><a href="https:&#x2F;&#x2F;mail.gnome.org&#x2F;archives&#x2F;desktop-devel-list&#x2F;2019-May&#x2F;msg00066.html" rel="nofollow">https:&#x2F;&#x2F;mail.gnome.org&#x2F;archives&#x2F;desktop-devel-list&#x2F;2019-May&#x2F;...</a>
        • defen4 hours ago
          I&#x27;m fully on-board with not using master-slave terminology. I work in the embedded space where those terms were and still are frequently used, and I support not using them any more. But I&#x27;ve been using git pretty much since it was released and I&#x27;ve never heard anyone refer to a &quot;slave repo&quot; or &quot;slave branch&quot;. It&#x27;s always been local repo, local branch, etc. I fully believe these sorts of digital hermeneutics (e.g. using a 26-year-old mailing list post to &quot;prove&quot; something, when actual usage is completely different) drive division and strife, all because some people want to use it to acquire status&#x2F;prestige.
        • themafia4 hours ago
          Does git use &quot;slave?&quot;<p>Then does simply performing a search on bitkeepers documents for &quot;slave&quot; then automatically imply any particular terminology &quot;came from bitkeeper?&quot;<p>Did they take it from bitkeeper because they prefer antiquated chattel slavery terminology? Is there any actual documents that show this &#x2F;intention&#x2F;?<p>Or did they take it because &quot;master&quot; without slave is easily recognizable as described above which accurately describes how it&#x27;s _actually_ implemented in git.<p>Further git is distributed. Bitkeeper was not.<p>This is just time wasting silliness.
      • imdsm6 hours ago
        I&#x27;ll change my default branches to main when Masterclass change their name to Mainclass
        • zugi2 hours ago
          And mastering a subject is changed to maining it?
      • ffsm86 hours ago
        Yeah, with replica it made a little sense. Was still silly, but at least the official master&#x2F;slave terminology actually didn&#x27;t fully make sense either... So the replica rebrand felt justified to me.<p>With git it was basically entirely driven by SJW that felt empowered by people accepting the replica rebrand
        • r14c6 hours ago
          imo the `main` thing was mostly driven by people trying to appease the social justice crowd without understanding much about the movement. Its a bit of woo in my mind because there are still systemic injustices out there that are left uncontested, and using main doesn&#x27;t really contest anything substantial.<p>I don&#x27;t really care what the default branch is called tho so I&#x27;m willing to play along.
    • kridsdale16 hours ago
      At Meta, when this mass push for the rename happened across the industry, a few people spent nearly the full year just shepherding the renaming of master to main, and white box&#x2F;black box to allowlist&#x2F;blocklist.<p>This let them claim huge diff counts and major contributions to DEI and get promos.
      • yokoprime4 hours ago
        This is why diffs &#x2F; LoC is a terrible metric. It shows nothing other than a willingness to push large changesets upstream.
      • jihadjihad6 hours ago
        Same at my org at the time, <i>blacklist</i> was nixed, no matter how many times the question, &quot;What color is ink on a page?&quot; was brought up.
        • 8organicbits5 hours ago
          Seems like a bad faith question, unfortunate that it was asked multiple times. Blacklist is derived from a definition where black means &quot;evil, bad, or undesirable&quot;. When you say that ink is black, you&#x27;re using a different definition, which relates to color. I don&#x27;t know if I see the objection to blackbox, which uses a definition of &quot;unknown&quot;. Personally, I think the harm is small but I look to people of color for guidance and prefer the more descriptive deny-list where I can. Cuts down on possible confusion for non-native English speakers too.
          • reenorap4 hours ago
            The irony is that the term &quot;Black&quot; was precisely chosen by Black civil rights activists in the 1960s. This wasn&#x27;t a term given by white people, it was specifically chosen by Blacks, because of its negative connotations. They wanted to embrace its negative connotations and turn it on its head, and that&#x27;s where terms like &quot;Black is beautiful&quot; came from. They didn&#x27;t want to be ashamed of it, that&#x27;s why they embraced it. Black was not a term of shame, it was a term of power.<p>Now, the left wing activists have turned it on its head again, and now saying that the term &quot;black&quot; is shameful and racist. It&#x27;s bizarre how ignorant people are who say the term &quot;blacklist&quot; is racist.
        • layer85 hours ago
          &gt; What color is ink on a page?<p>Middle gray, according to modern UX designers. ;)
          • pmontra4 hours ago
            You are lucky. It&#x27;s often light gray on thin fonts.
        • pbhjpbhj5 hours ago
          The colour of the ink is not where &quot;blacklist&quot; comes from though? It&#x27;s not from supposed skin colour either...<p>Blocklist makes more sense in most scenarios.
      • tucnak6 hours ago
        They measure LoC contributions at FB?
    • yokoprime4 hours ago
      Im just tuning out of the whole master vs main discussion. I use whatever is the default branch name of my current project OR what git init gives me. When &#x2F; if git init produces a default branch named main, i&#x27;ll use that.
    • doetoe4 hours ago
      In current times, there will be more people offended that some prefer to use &quot;main&quot; rather than &quot;master&quot;, than people that will be offended if &quot;master&quot; is used
    • tom_5 hours ago
      Thank you for creating the containment thread.
    • botusaurus4 hours ago
      not on your mind, yet you found the time to write this comment<p>are you sure this is about time&#x2F;breaking and not &quot;being told how to think&quot;?
    • drcongo4 hours ago
      Haven&#x27;t got enough hours to type fewer characters, but have got plenty of time to go karma-fishing about it on an almost barely tangentially relevant HN thread. Cool.
    • hungryhobbit5 hours ago
      &gt; But, my fear is it&#x27;ll subtly break something and I just don&#x27;t have enough hours left in my life to accept yet unknown risk that it&#x27;ll cost me even more hours,<p>Yeah, it&#x27;s not like 99% of the world has already switched from master to main already (without any major problems) ...
      • stevekemp4 hours ago
        You&#x27;ll find CI&#x2F;CD automation <i>probably</i> needs to be updated. (Triggering different actions when merges to the default branch happen, or perhaps just deployments.)<p>These are the kinda local things that the parent was probably referring to.
    • TacticalCoder6 hours ago
      [flagged]
      • maest5 hours ago
        The whole master&#x2F;main thing is a dinstinctly American culture war issue which, unfortunately, infected the rest of the world.
  • bgfjhgghhhg7 hours ago
    [dead]
  • huflungdung1 hour ago
    [dead]
  • morissette8 hours ago
    [flagged]
    • sidsud8 hours ago
      agree, this just seems click-baity. if you&#x27;re familiar with the UNIX Way, this is a one-liner you&#x27;d naturally write. CIA leaked docs mention and a blog post for this?
      • djmips6 hours ago
        the Clandestine allure for clicks for sure but you know what - the comments have been pretty interesting.