Urgent.News

What's breaking now, across thousands of outlets.

Tech

My local repos were full of zombie branches and git never told me which ones were safe to delete

Last week I ran git branch in one of my older working trees and got back forty-some local branches. Forty. I work on maybe three things at a time. The rest were residue: half of them were merged into main months ago, a few tracked remote branches that someone had already deleted on the server, and the rest I genuinely did not recognize anymore. The problem with this pile is not disk space. A…

Last week, the author ran the command 'git branch' in one of their older working directories and was overwhelmed by the sheer number of local branches listed - forty-some. This clutter was not a concern for disk space, but rather it made other git commands less efficient. Git log --all became noisy, tab completion for branch names stopped working, and the task of pruning became a daunting prospect, as deleting a branch that was thought to be dead could lead to a headache weeks later when a commit was needed.

The author attempted the usual methods, such as using git branch --merged main, but it also listed the current branch and deleting a branch based on the output could lead to disastrous consequences. Another method, git branch -vv, showed [gone] for branches whose upstream had vanished, but it required manual interpretation of the output.

No single command provided reasons per branch, which led the author to create a Python script named git-stale. This tool, consisting of a 5,092-byte single file, imports four modules from Python's standard library and runs without any additional installations. The core functionality of the script checks if a branch is merged into the default branch, if its upstream branch no longer exists, or if its last commit is older than a specified threshold.

The script uses a thin wrapper-over-git approach, asking git itself to determine the truth, rather than introducing potential bugs by attempting to replicate merge-base logic or parse the index.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Next.js 16's Turbopack is 2.5x faster, but the bundler is only 4% of your build

Next.js 16 makes Turbopack the default bundler and puts a number on it: builds 2 to 5 times faster than webpack. I wanted to know whether that holds on something bigger than the starter template, and…

  • Next.js 16 introduces Turbopack as default bundler, 2.5-5x faster than webpack
  • Bundler only 4% of total build time, other phases consume majority
  • Turbopack's caching accelerates compiling step 19x, but total build time only 4x faster

More from Friday 11 September →