Package: git-delete-merged-branches
git-delete-merged-branchesA convenient command-line tool helping you keep repositories clean.Installation#pipinstallgit-delete-merged-branchesIf you are using one of the distributions below, you can installgit-delete-merged-branchesthrough the respective package manager, e.g.:Arch Linux (AUR)—# yay -S git-delete-merged-branchesDebian GNU/Linux (sid)—# apt install git-delete-merged-branchesGentoo Linux—# emerge -av dev-vcs/git-delete-merged-branchesHomebrew—# brew install git-delete-merged-branchesNixOSExample#git-delete-merged-branchesDo you want to run "git remote update --prune" for 1 remote(s):- originUpdate? [y/N] yDo you want to run "git pull --ff-only" for 1 branch(es):- masterPull? [y/N] yYou 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-ciDelete? [y/N] y6 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-ciDelete? [y/N] yTo 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-ci6 remote branch(es) deleted.FeaturesSupports deletion of both local and remote branchesDetects multiple forms of de-facto merges
(rebase merges,
squash merges (needs--effort=3),
single or range cherry-picks…
leveraginggit cherry)Supports workflows with multiple release branches, e.g. only delete branches that have been merged toallofmaster,devandstagingQuick interactive configurationProvider agnostic: Works with GitHub, GitLab, Gitea and any other Git hostingTakes safety seriouslySafetyDeletion is a sharp knife that requires care.
Whilegit reflogwould have your back in most cases,git-delete-merged-branchestakes safety seriously.Here's whatgit-delete-merged-branchesdoes for your safety:No branches are deleted without confirmation or passing--yes.Confirmation defaults to "no"; plain[Enter]/[Return]does not delete.git pushis used with--force-with-leaseso if the server and you have a different understanding of that branch, it is not deleted.There is no use ofos.systemor shell code to go wrong.With--dry-runyou can get a feel for the changes thatgit-delete-merged-brancheswould be making to your branches.Show any Git commands run using--verbose.Best PracticesWhen 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.mastershould probably track original upstream'smasterrather thanmasterof your fork.Consider keeping your fork's remotemasterup to date (usinggit push).When using GitHub:You can make GitHubdelete branches of merged pull requestsfor you, to savegit-delete-merged-branchessome work on the remote side, if you like.Name clash on "git-delete-merged-branches" with git-extrasUtility collectiongit-extrasprovides asimple shell script namedgit-delete-merged-branchesthat competes for commandgit-delete-merged-brancheswhen both software packages are installed.To address this conflict you can:a) Invokepython3 -m git_delete_merged_branchesinstead ofgit-delete-merged-branchesb) Invoke commandgit-dmbinstead ofgit-delete-merged-branchesc) Control path resolution order through environment variable$PATHd) Invokegit-delete-merged-brancheswith its absolute path.
You can runwhich -a git-delete-merged-branchesto see where it's located.SupportPlease report any bugs that you find.Like this tool?  Support it with a star!