npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prune-gone-branches

v1.0.0

Published

Delete local git branches whose remote branch is gone. Dry run by default, protects main/master, zero dependencies.

Readme

prune-gone-branches

npm version CI license

Delete local git branches whose remote branch is gone. Dry run by default, never touches main, master, develop, or the branch you are on. Zero dependencies.

After a PR is merged and its branch deleted on GitHub, the local copy sticks around. A few weeks later you have forty of them. This tool finds every branch whose upstream reports [gone] and removes them in one go.

$ npx prune-gone-branches
Branches whose upstream is gone (3):
  feat/login-form   (a1b2c3d, was origin/feat/login-form)
  fix/typo          (e4f5a6b, was origin/fix/typo)
  chore/deps        (c7d8e9f, was origin/chore/deps)

Dry run. Re-run with --delete to remove them, add --force for unmerged branches.

$ npx prune-gone-branches --delete
Deleted feat/login-form
Deleted fix/typo
Deleted chore/deps

Install

npm install -g prune-gone-branches
# or run without installing
npx prune-gone-branches

Requires Node 18 or newer and git on your PATH.

CLI

prune-gone-branches [options]

  -d, --delete           Delete the branches (default is a dry run)
  -f, --force            Use "git branch -D" so unmerged branches are deleted too
      --no-fetch         Skip "git fetch --prune"
  -r, --remote <name>    Only consider branches tracking this remote
  -p, --protect <names>  Comma-separated names or patterns never to delete
                         (default: main,master,develop; pass "" to disable)
      --json             Print the result as JSON
  -q, --quiet            Print nothing; rely on the exit code
  -h, --help             Show help
  -v, --version          Show version

Exit codes: 0 nothing to do or every deletion succeeded, 1 dry run found branches or some deletions failed, 2 usage or git error.

How it decides

  1. Runs git fetch --prune so remote-tracking refs match the server. Skip with --no-fetch.
  2. Lists local branches whose upstream tracking status is [gone], meaning the branch was pushed and the remote branch has since been deleted.
  3. Skips the checked-out branch and anything matching --protect.
  4. With --delete, runs git branch -d on each. Git refuses unmerged branches, which the tool reports. Add --force to use git branch -D.

Branches that were never pushed are not touched. They have no upstream, so they cannot be "gone".

Examples

# See what would be deleted
prune-gone-branches

# Delete merged ones, keep anything unmerged
prune-gone-branches -d

# Delete everything whose remote is gone, merged or not
prune-gone-branches -d -f

# Protect release branches too
prune-gone-branches -d -p "main,master,release/*"

# Only look at branches tracking a specific remote
prune-gone-branches -d -r origin

Git alias

git config --global alias.gone '!npx prune-gone-branches'
# then
git gone        # dry run
git gone -d     # delete

Programmatic API

import { findGoneBranches, pruneGoneBranches } from "prune-gone-branches";

const { gone, skipped } = findGoneBranches({ cwd: "/path/to/repo" });
// gone: [{ name, upstream, sha }], skipped: [{ name, reason }]

const result = pruneGoneBranches({ cwd: "/path/to/repo", delete: true, force: false });
// result.deleted, result.failed, result.skipped, result.dryRun

Options: cwd, fetch (default true), remote, protect (default ["main", "master", "develop"]), delete (default false), force (default false). Git failures throw a GitError with the failing arguments attached.

Both ESM and CommonJS are supported, with TypeScript types included.

License

MIT