git-delete-merged-branches is a free, open source frameworks & platforms project written in Python and released under GPL-3.0. It has 915 GitHub stars, 23 forks and 7 open issues, and was last pushed 7 days ago. On this registry it ranks #73 of 78 tracked projects in Frameworks & Platforms, with 5 head-to-head comparisons available.

What is git-delete-merged-branches?

git-delete-merged-branches is a GPL-3.0-licensed Python command-line tool that removes already-merged local and remote Git branches, written for developers and maintainers who want their repositories kept clean without pruning branch lists by hand.

What it is

The project is a convenience command-line tool that helps keep repositories clean. It ships as a Python package on PyPI, is mirrored into the package managers of several Linux distributions plus Homebrew, MacPorts and NixOS, and works against any Git repository regardless of where it is hosted. Its topic list places it squarely in developer tooling for Git housekeeping and automation.

The problem it solves is the slow accumulation of branches that have already served their purpose. Git's own git branch -d only removes branches it regards as merged, and it has no notion of the de-facto merges that modern workflows produce, while removing a branch on the remote means issuing git push deletion commands one at a time. The tool replaces that manual combination of git branch, git branch -r and per-branch git push judgement with a single command that surveys local and remote branches together and asks for confirmation before acting.

Key capabilities

  • Supports deletion of both local and remote branches, reporting counts such as "6 local branch(es) deleted" and then repeating the process for branches on origin.
  • Detects multiple forms of de-facto merges, including rebase merges, squash merges (which need --effort=3) and single or range cherry-picks, leveraging git cherry rather than relying on ancestry alone.
  • Supports workflows with multiple release branches, for example deleting only branches that have been merged to all of master, dev and staging.
  • Can run git remote update --prune and git pull --ff-only as optional preliminary steps so that branch state is current before anything is removed.
  • Is provider agnostic and works with GitHub, GitLab, Gitea and any other Git hosting.
  • Takes safety seriously: nothing is deleted without confirmation or an explicit --yes, confirmation defaults to no so a plain Enter does not delete, git push uses --force-with-lease, no os.system or shell code is involved, and --dry-run shows what would change.

Who uses it and how

  • Individual developers tidying a working clone after feature branches have landed, answering the interactive prompts batch by batch.
  • Teams maintaining several long-lived release branches, where being merged into one target is not sufficient evidence and every one of master, dev and staging must agree.
  • Contributors to projects hosted on GitHub, GitLab, Gitea or a self-managed Git server, since the tool makes no provider-specific assumptions.
  • Users on the distributions where it is packaged, installing through yay -S git-delete-merged-branches on Arch Linux, apt install git-delete-merged-branches on Debian and Ubuntu, emerge, xbps-install, brew, port or nix-shell.
  • Scripted cleanup that passes --yes to bypass prompts, or --dry-run to preview a change first.

Getting started

Install with pip install git-delete-merged-branches, or use the relevant distribution package manager command listed above. Then run git-delete-merged-branches inside the repository to be cleaned and answer the prompts.

How it compares

No comparable or competing tools are named in the facts provided, so this entry stands alone in this registry. Any claim about how it relates to alternatives would go beyond the available information.

When to use it — and when not to

It requires no database, object storage or mail server: it is a local command-line tool that talks to a Git clone and its remotes, so the operational burden is limited to having Python or a distribution package available. Squash-merge detection only works when --effort=3 is passed, and the default prompts make it unsuitable for unattended runs unless --yes is used. Anyone who wants a hosted service or a graphical interface, or who is unwilling to let a tool delete remote branches on their behalf, should look elsewhere.

project readme (upstream, from github) — read inline

pre-commit Run the test suite Packaging status

git-delete-merged-branches

A convenient command-line tool helping you keep repositories clean.

Installation

# pip install git-delete-merged-branches

If you are using one of the distributions below, you can install git-delete-merged-branches through the respective package manager, e.g.:

Distribution Command
Arch Linux (AUR) yay -S git-delete-merged-branches
Debian GNU/Linux (>=bookworm) apt install git-delete-merged-branches
Gentoo Linux emerge -av dev-vcs/git-delete-merged-branches
Homebrew brew install git-delete-merged-branches
MacPorts port install py-git-delete-merged-branches
NixOS nix-shell -p git-delete-merged-branches
Ubuntu (>=lunar/23.04) apt install git-delete-merged-branches
Void Linux xbps-install -S git-delete-merged-branches

Example

# git-delete-merged-branches
Do you want to run "git remote update --prune" for 1 remote(s):
  - origin

Update? [y/N] y

Do you want to run "git pull --ff-only" for 1 branch(es):
  - master

Pull? [y/N] y

You are about to delete 6 local branch(es):
  - improve-setup-py
  - issue-12-enable-ci-for-pull-requests
  - issue-5-fix-waste-of-one-second-per-service
  - keep-github-actions-up-to-date
  - refactoring-one
  - simple-ci

Delete? [y/N] y

6 local branch(es) deleted.
You are about to delete 6 remote branch(es):
  - origin/improve-setup-py
  - origin/issue-12-enable-ci-for-pull-requests
  - origin/issue-5-fix-waste-of-one-second-per-service
  - origin/keep-github-actions-up-to-date
  - origin/refactoring-one
  - origin/simple-ci

Delete? [y/N] y
To github.com:hartwork/wait-for-it.git
 - [deleted]         improve-setup-py
 - [deleted]         issue-12-enable-ci-for-pull-requests
 - [deleted]         issue-5-fix-waste-of-one-second-per-service
 - [deleted]         keep-github-actions-up-to-date
 - [deleted]         refactoring-one
 - [deleted]         simple-ci

6 remote branch(es) deleted.

Features

  • Supports deletion of both local and remote branches
  • Detects multiple forms of de-facto merges (rebase merges, squash merges (needs --effort=3), single or range cherry-picks… leveraging git cherry)
  • Supports workflows with multiple release branches, e.g. only delete branches that have been merged to all of master, dev and staging
  • Quick interactive configuration
  • Provider agnostic: Works with GitHub, GitLab, Gitea and any other Git hosting
  • Takes safety seriously

Safety

Deletion is a sharp knife that requires care. While git reflog would have your back in most cases, git-delete-merged-branches takes safety seriously.

Here's what git-delete-merged-branches does for your safety:

  • No branches are deleted without confirmation or passing --yes.
  • Confirmation defaults to "no"; plain [Enter]/[Return] does not delete.
  • git push is used with --force-with-lease so if the server and you have a different understanding of that branch, it is not deleted.
  • There is no use of os.system or shell code to go wrong.
  • With --dry-run you can get a feel for the changes that git-delete-merged-branches would be making to your branches.
  • Show any Git commands run using --verbose.

Best Practices

When the repository is a fork (with an upstream remote and a fork remote):

  • Make sure that release branches are tracking the right remote, e.g. master should probably track original upstream's master rather than master of your fork.
  • Consider keeping your fork's remote master up to date (using git push).

When using GitHub:

Name clash on "git-delete-merged-branches" with git-extras

Utility collection git-extras provides a simple shell script named git-delete-merged-branches that competes for command git-delete-merged-branches when both software packages are installed.

To address this conflict you can:

  • a) Invoke python3 -m git_delete_merged_branches instead of git-delete-merged-branches
  • b) Invoke command git-dmb instead of git-delete-merged-branches
  • c) Control path resolution order through environment variable $PATH
  • d) Invoke git-delete-merged-branches with its absolute path. You can run which -a git-delete-merged-branches to see where it's located.

Support

Please report any bugs that you find.

Like this tool? Support it with a star!

Frequently asked questions

Is git-delete-merged-branches free to use?

git-delete-merged-branches is open source under the GPL-3.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does git-delete-merged-branches do?

:fire: Command-line tool to delete merged Git branches

What is git-delete-merged-branches written in?

git-delete-merged-branches is primarily written in Python. Its source is publicly available at https://github.com/hartwork/git-delete-merged-branches, and it has 915 GitHub stars.