Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔥 Command-line tool to delete merged Git branches

License

NotificationsYou must be signed in to change notification settings

hartwork/git-delete-merged-branches

Repository files navigation

pre-commitRun the test suitePackaging 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 installgit-delete-merged-branches through the respective package manager, e.g.:

DistributionCommand
Arch Linux (AUR)yay -S git-delete-merged-branches
Debian GNU/Linux (>=bookworm)apt install git-delete-merged-branches
Gentoo Linuxemerge -av dev-vcs/git-delete-merged-branches
Homebrewbrew install git-delete-merged-branches
MacPortsport install py-git-delete-merged-branches
NixOSnix-shell -p git-delete-merged-branches
Ubuntu (>=lunar/23.04)apt install git-delete-merged-branches
Void Linuxxbps-install -S git-delete-merged-branches

Example

#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.

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…leveraginggit cherry)
  • Supports workflows with multiple release branches, e.g. only delete branches that have been merged toall ofmaster,dev andstaging
  • 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.Whilegit reflog would have your back in most cases,git-delete-merged-branches takes safety seriously.

Here's whatgit-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 ofos.system or shell code to go wrong.
  • With--dry-run you can get a feel for the changes thatgit-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'smasterrather thanmaster of your fork.
  • Consider keeping your fork's remotemaster up to date (usinggit push).

When using GitHub:

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

Utility collectiongit-extras provides asimple shell script namedgit-delete-merged-branchesthat competes for commandgit-delete-merged-branches when both software packages are installed.

To address this conflict you can:

  • a) Invokepython3 -m git_delete_merged_branches instead ofgit-delete-merged-branches
  • b) Invoke commandgit-dmb instead ofgit-delete-merged-branches
  • c) Control path resolution order through environment variable$PATH
  • d) Invokegit-delete-merged-branches with its absolute path.You can runwhich -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!


[8]ページ先頭

©2009-2025 Movatter.jp