Socket
Book a DemoInstallSign in
Socket

git-prune-branches

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-prune-branches

Delete local git branches that have been merged and removed on the remote

1.1.2
latest
Source
npmnpm
Version published
Weekly downloads
7
133.33%
Maintainers
1
Weekly downloads
 
Created
Source

git-prune-branches

List or remove local tracked branches, which are deleted from the remote.

It's a fork of git-removed-branches with an interactive prompt, and the ability to retry deleting branches with --force

Addresses questions, like:

Demo

Why?

Because I'm tired of doing every time git fetch -p, git branch -r, git branch and keep comparing which branches are gone from the GitHub, but still available locally and doing git branch -D ${branch_name} on each of them, one by one.

What does it do?

This command will compare your local branches with remote and show you branches that are no longer available on remote but are still presented in your local repository. You can also use it to view and delete all (remotely) removed branches in one go using --prune-all flag.

Prompt with list of branches, allowing arbitrary selection

This command works without the need to run git fetch -p, but a working network connection to your remote is required. If no connection can be established with the remote repository, then local information about your remote will be used instead. If your local repository is not in sync with the remote repository, it will warn you about it.

Installation

NPM

npm install -g git-prune-branches

Please install a package globally with -g flag so that you can use it directly as a sub command of git, like this:

git prune-branches

NPX

It's also possible to use package through npx without installing:

npx git-prune-branches

Usage

git prune-branches

This command will look through the branches that are no longer available on the remote and display them. In case you haven't run git fetch -p, it will warn you to do so.

Confirmation prompt

Auto-removal

To delete all local branches without choosing which ones, and without confirmation, use --prune-all or -p flag

git prune-branches --prune-all

This command will compare your local branches to the remote ones and remove, those which do not exist anymore on the remote side.

Custom remote

If you have configured remote alias to something different than 'origin', you can use --remote or -r flag to specify the name of the remote. e.g., to specify remote to be upstream, you can use:

git prune-branches --remote upstream

Forcing removal

If you get an error when trying to delete branches:

The branch {branch_name} is not fully merged.

you can force deletion by using --force flag or the -f alias

git prune-branches --prune-all --force

Retrying with --force

If any branches fail to delete when the --force flag is not used, git-prune-branches will offer to retry and delete them again using --force.

Skipping confirmation

You can skip the confirmation prompts with --yes or the shortcut -y:

git prune-branches -y

Version

To print the version:

git prune-branches --version

Troubleshooting

If you encounter error ERR_CHILD_PROCESS_STDIO_MAXBUFFER it is possible that your repository contains too many branches (more then 3382—see discussion).

You can fix this by specifying NODE_MAX_BUFFER environment variable. For example:

NODE_MAX_BUFFER=1048576 git prune-branches

Development

Testing

This project uses Vitest for testing. The tests create a temporary git repository and verify the behavior of the tool in different scenarios.

Run tests in watch mode

pnpm test

Run tests once

pnpm test:once

Building

Build the TypeScript source:

pnpm build

Linting and Formatting

pnpm lint
pnpm format

Credit

Forked from git-removed-branches by Maks Nemisj @nemisj

Keywords

git

FAQs

Package last updated on 01 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.