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 🙏

© 2024 – Pkg Stats / Ryan Hefner

deletable-branches

v0.1.9

Published

List remote tracking branches in a Git repo that were in PRs that were squashed and merged into master.

Downloads

17

Readme

deletable-branches

List remote tracking branches in a Git repo in the current directory that were in PRs that were squashed and merged into master, and other notions of remote tracking branches that could be deleted.

Run

Run with

npx deletable-branches --token-file /file/w/GitHubPersonalAccessToken --help

Example

The repo delebran/trepo-1 has had pull requests for the remote branches s0, s1, and s2 squashed and merged into master, but they were not deleted on GitHub. They won't show up in the output of git branch -r --merged, because they were squashed.

You could run

npx deletable-branches --token-file /file/w/GitHubPersonalAccessToken --merged --not-open --squashed-diffs

to list remote tracking branches that:

  1. Are included in pull requests on GitHub that were merged into master (--merged),
  2. Are not included in any open pull requests on GitHub (--not-open), and
  3. Introduced changes that can be found in the history of master (--squashed-diff).

--squashed-diff is based on the local Git commands used by git-delete-squashed. --merged, --not-open, and --closed use the GitHub GraphQL API.

$ npx deletable-branches -t /file/w/GitHubPersonalAccessToken --merged --not-open --squashed-diff
npx: installed 8 in 1.895s
550e374f8a750e843816a494ed8a552cb9b2de80 s0
cadc0fe782925469e30390d17091d703b8469395 s1
dbaa5bfdb3c089fd0f0cddd3ad326dec66b6efde s2

$ npx deletable-branches -t /file/w/GitHubPersonalAccessToken --closed --not-open
npx: installed 8 in 1.045s
fa35c685665d1b2921497faa8ea0df54e433ec99 c0
e3bec591671413f17adc574642d57e72639b8ec4 c1
3b4ea38542f4b0d8e3a43982be060b97264535c1 c2

$ git branch -r --format="%(objectname) %(refname:lstrip=-1)" --list
f1737a94a41f2856a105f3dd70627975025f47e4 HEAD
fa35c685665d1b2921497faa8ea0df54e433ec99 c0
e3bec591671413f17adc574642d57e72639b8ec4 c1
3b4ea38542f4b0d8e3a43982be060b97264535c1 c2
55e188c1c5379b3da82c1165473ce7e5a37ab432 f0
ef7637a8a92b80709fd7990285512dd007daee69 f1
b4d87ecd472599241c8fe0ce61fb21e5dbc6716c m0
78793e9d43c2dc704b20c876d3c6883b2ae040fe m1
7db6474bbdbd21c8bbf45e8f9b3dce03199cf2f9 m2
f1737a94a41f2856a105f3dd70627975025f47e4 master
9f1e3c37043c0a341484548262053537665d73ac o0
1012e3a74ca16a38513af7b1a2bc20ed1bdfdec6 o1
586eb4ccfe50330fc84388e4f81282637b19514e o2
550e374f8a750e843816a494ed8a552cb9b2de80 s0
cadc0fe782925469e30390d17091d703b8469395 s1
dbaa5bfdb3c089fd0f0cddd3ad326dec66b6efde s2

$ git branch -r --format="%(objectname) %(refname:lstrip=-1)" --list --merged
f1737a94a41f2856a105f3dd70627975025f47e4 HEAD
b4d87ecd472599241c8fe0ce61fb21e5dbc6716c m0
78793e9d43c2dc704b20c876d3c6883b2ae040fe m1
7db6474bbdbd21c8bbf45e8f9b3dce03199cf2f9 m2
f1737a94a41f2856a105f3dd70627975025f47e4 master

Without --merged, --not-open, --squashed-diffs, or --closed, deletable-branches prints all the remote tracking branches.

Deleting branches

You could use the output to delete branches with, for example,

npx deletable-branches -t /file/w/GitHubPersonalAccessToken \
  --merged --not-open --squashed-diff \
  | awk '{print $2}' \
  | while read b ; do \
  git push --force origin :${b} ; done

GitHub Personal Access Token

You need a GitHub Personal Access Token to use this script.

Caveats

Slashes

This probably will not work well when remotes have slashes (/) in their names. It does handle slashes in remote branch names. So a remote of my/origin as opposed to origin will probably not be picked up, but a branch name of branch/name as opposed to branch-name should be.

Only for GitHub organizations

The calls to the GitHub API made by --merged, --not-open, and --closed only work when the repo you're in is within a GitHub organization/team. If you use the option --squashed-diffs, and not --merged, --not-open, or --closed, it should work on any repo.